Attributes.h revision 49f6060f16aec4024d644a6ec4ddd3de9b3e8821
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 "llvm/Support/MathExtras.h" 2322bd64173981bf1251c4b3bfc684207340534ba3Bill Wendling#include <cassert> 2458d74910c6b82e622ecbb57d6644d48fec5a5c0fChris Lattner#include <string> 256091ebd172a16a10f1ea66061a5fa7cbf5139e56Reid Spencer 266091ebd172a16a10f1ea66061a5fa7cbf5139e56Reid Spencernamespace llvm { 27d426a642a23a234547cbc7061f5bfec157673249Bill Wendling 28702cc91aa1bd41540e8674921ae7ac89a4ff061fBill Wendlingclass AttrBuilder; 29f6670729aabc1fab85238d2b306a1c1767a807bbBill Wendlingclass AttributeImpl; 30a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendlingclass Constant; 312c79ecbd704c656178ffa43d5a58ebe3ca188b40Bill Wendlingclass LLVMContext; 32ad9a9e15595bc9d5ba1ed752caf8572957f77a3dDuncan Sandsclass Type; 33ad9a9e15595bc9d5ba1ed752caf8572957f77a3dDuncan Sands 341d3dcfe4246b4d45fa78a8dfd0a11c7fff842c15Bill Wendling//===----------------------------------------------------------------------===// 3527107f6ab4627fa38bcacad6757ed6d52910f880Bill Wendling/// \class 3627107f6ab4627fa38bcacad6757ed6d52910f880Bill Wendling/// \brief Functions, function parameters, and return types can have attributes 371d3dcfe4246b4d45fa78a8dfd0a11c7fff842c15Bill Wendling/// to indicate how they should be treated by optimizations and code 381d3dcfe4246b4d45fa78a8dfd0a11c7fff842c15Bill Wendling/// generation. This class represents one of those attributes. It's light-weight 391d3dcfe4246b4d45fa78a8dfd0a11c7fff842c15Bill Wendling/// and should be passed around by-value. 40034b94b17006f51722886b0f2283fb6fb19aca1fBill Wendlingclass Attribute { 416765834754cbb3cb0f15b4b15e98c5e73fa50066Bill Wendlingpublic: 421d3dcfe4246b4d45fa78a8dfd0a11c7fff842c15Bill Wendling /// This enumeration lists the attributes that can be associated with 431d3dcfe4246b4d45fa78a8dfd0a11c7fff842c15Bill Wendling /// parameters, function results or the function itself. 44f3d1500ab2c7364d3d0fb73a7e1b8c6339ab48b1Bill Wendling /// 451d3dcfe4246b4d45fa78a8dfd0a11c7fff842c15Bill Wendling /// Note: uwtable is about the ABI or the user mandating an entry in the 4611d00420e42ba88c3b48cab997965a7be79315e2Bill Wendling /// unwind table. The nounwind attribute is about an exception passing by the 4711d00420e42ba88c3b48cab997965a7be79315e2Bill Wendling /// function. 48f3d1500ab2c7364d3d0fb73a7e1b8c6339ab48b1Bill Wendling /// 4911d00420e42ba88c3b48cab997965a7be79315e2Bill Wendling /// In a theoretical system that uses tables for profiling and sjlj for 5011d00420e42ba88c3b48cab997965a7be79315e2Bill Wendling /// exceptions, they would be fully independent. In a normal system that uses 5111d00420e42ba88c3b48cab997965a7be79315e2Bill Wendling /// tables for both, the semantics are: 52f3d1500ab2c7364d3d0fb73a7e1b8c6339ab48b1Bill Wendling /// 5311d00420e42ba88c3b48cab997965a7be79315e2Bill Wendling /// nil = Needs an entry because an exception might pass by. 5411d00420e42ba88c3b48cab997965a7be79315e2Bill Wendling /// nounwind = No need for an entry 5511d00420e42ba88c3b48cab997965a7be79315e2Bill Wendling /// uwtable = Needs an entry because the ABI says so and because 5611d00420e42ba88c3b48cab997965a7be79315e2Bill Wendling /// an exception might pass by. 5711d00420e42ba88c3b48cab997965a7be79315e2Bill Wendling /// uwtable + nounwind = Needs an entry because the ABI says so. 5811d00420e42ba88c3b48cab997965a7be79315e2Bill Wendling 59629fb82419d9bfff6ae475363bcce66192dfcc8eBill Wendling enum AttrKind { 605a0eeb5a9d727940b1dbe8dff6e9aa292ada0f6aBill Wendling // IR-Level Attributes 61480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling None, ///< No attributes have been set 62480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling AddressSafety, ///< Address safety checking is on. 63480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling Alignment, ///< Alignment of parameter (5 bits) 646765834754cbb3cb0f15b4b15e98c5e73fa50066Bill Wendling ///< stored as log2 of alignment with +1 bias 65f6670729aabc1fab85238d2b306a1c1767a807bbBill Wendling ///< 0 means unaligned (different from align(1)) 66480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling AlwaysInline, ///< inline=always 67480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling ByVal, ///< Pass structure by value 68480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling InlineHint, ///< Source said inlining was desirable 69480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling InReg, ///< Force argument to be passed in register 709a419f656e278b96e9dfe739cd63c7bff9a4e1fdQuentin Colombet MinSize, ///< Function must be optimized for size first 71480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling Naked, ///< Naked function 72480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling Nest, ///< Nested function static chain 73480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling NoAlias, ///< Considered to not alias after call 74480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling NoCapture, ///< Function creates no aliases of pointer 7567ae13575900e8efd056672987249fd0adbf5e73James Molloy NoDuplicate, ///< Call cannot be duplicated 76480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling NoImplicitFloat, ///< Disable implicit floating point insts 77480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling NoInline, ///< inline=never 78480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling NonLazyBind, ///< Function is called early and/or 793a106e60366a51b4594ec303ff8dbbc58913227fBill Wendling ///< often, so lazy binding isn't worthwhile 80480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling NoRedZone, ///< Disable redzone 81480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling NoReturn, ///< Mark the function as not returning 82480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling NoUnwind, ///< Function doesn't unwind stack 83480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling OptimizeForSize, ///< opt_size 84480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling ReadNone, ///< Function does not access memory 85480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling ReadOnly, ///< Function only reads from memory 86480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling ReturnsTwice, ///< Function can return twice 87480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling SExt, ///< Sign extended before/after call 88480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling StackAlignment, ///< Alignment of stack for function (3 bits) 896765834754cbb3cb0f15b4b15e98c5e73fa50066Bill Wendling ///< stored as log2 of alignment with +1 bias 0 906765834754cbb3cb0f15b4b15e98c5e73fa50066Bill Wendling ///< means unaligned (different from 91f6670729aabc1fab85238d2b306a1c1767a807bbBill Wendling ///< alignstack=(1)) 92480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling StackProtect, ///< Stack protection. 93480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling StackProtectReq, ///< Stack protection required. 94114baee1fa017daefad2339c77b45b9ca3d79a41Bill Wendling StackProtectStrong, ///< Strong Stack protection. 95480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling StructRet, ///< Hidden pointer to structure to return 96480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling UWTable, ///< Function must be in a unwind table 970319888773b36dd61d7d2283cb9a26cac1e5abe8Bill Wendling ZExt, ///< Zero extended before/after call 980319888773b36dd61d7d2283cb9a26cac1e5abe8Bill Wendling 993a4779a9211281a1d0c27c97037342329035a185NAKAMURA Takumi EndAttrKinds, ///< Sentinal value useful for loops 1003a4779a9211281a1d0c27c97037342329035a185NAKAMURA Takumi 1016f78fbbc630d2b86fb752574f5ad74473f57dfb1Chandler Carruth AttrKindEmptyKey, ///< Empty key value for DenseMapInfo 1026f78fbbc630d2b86fb752574f5ad74473f57dfb1Chandler Carruth AttrKindTombstoneKey ///< Tombstone key value for DenseMapInfo 1036765834754cbb3cb0f15b4b15e98c5e73fa50066Bill Wendling }; 1046765834754cbb3cb0f15b4b15e98c5e73fa50066Bill Wendlingprivate: 10527107f6ab4627fa38bcacad6757ed6d52910f880Bill Wendling AttributeImpl *pImpl; 10627107f6ab4627fa38bcacad6757ed6d52910f880Bill Wendling Attribute(AttributeImpl *A) : pImpl(A) {} 107d426a642a23a234547cbc7061f5bfec157673249Bill Wendlingpublic: 10827107f6ab4627fa38bcacad6757ed6d52910f880Bill Wendling Attribute() : pImpl(0) {} 1092c79ecbd704c656178ffa43d5a58ebe3ca188b40Bill Wendling 110c08a5ef6581f2c7550e92d31f63cd65ec29c39e0Bill Wendling /// \brief Return a uniquified Attribute object. 11116f95669ec814d98ce28ad514df603c01d662ee8Bill Wendling static Attribute get(LLVMContext &Context, ArrayRef<AttrKind> Kinds); 112034b94b17006f51722886b0f2283fb6fb19aca1fBill Wendling static Attribute get(LLVMContext &Context, AttrBuilder &B); 1132c79ecbd704c656178ffa43d5a58ebe3ca188b40Bill Wendling 114c08a5ef6581f2c7550e92d31f63cd65ec29c39e0Bill Wendling /// \brief Return a uniquified Attribute object that has the specific 115c08a5ef6581f2c7550e92d31f63cd65ec29c39e0Bill Wendling /// alignment set. 116c08a5ef6581f2c7550e92d31f63cd65ec29c39e0Bill Wendling static Attribute getWithAlignment(LLVMContext &Context, uint64_t Align); 117c08a5ef6581f2c7550e92d31f63cd65ec29c39e0Bill Wendling static Attribute getWithStackAlignment(LLVMContext &Context, uint64_t Align); 118c08a5ef6581f2c7550e92d31f63cd65ec29c39e0Bill Wendling 1191d3dcfe4246b4d45fa78a8dfd0a11c7fff842c15Bill Wendling /// \brief Return true if the attribute is present. 120629fb82419d9bfff6ae475363bcce66192dfcc8eBill Wendling bool hasAttribute(AttrKind Val) const; 1212e879bcd52583335c753c005d203bf2ffe8b67b5Bill Wendling 1221d3dcfe4246b4d45fa78a8dfd0a11c7fff842c15Bill Wendling /// \brief Return true if attributes exist 12305cc40d20c0f3b2f1bd5cb86ceb9f32d07cae110Bill Wendling bool hasAttributes() const; 1242e879bcd52583335c753c005d203bf2ffe8b67b5Bill Wendling 1251d3dcfe4246b4d45fa78a8dfd0a11c7fff842c15Bill Wendling /// \brief Returns the alignment field of an attribute as a byte alignment 126ef99fe8efaa6cb74c66e570a6ef467debca92911Bill Wendling /// value. 127e66f3d3ba0ea9f82f65a29c47fc37e997cbf0aceBill Wendling unsigned getAlignment() const; 128ef99fe8efaa6cb74c66e570a6ef467debca92911Bill Wendling 1291d3dcfe4246b4d45fa78a8dfd0a11c7fff842c15Bill Wendling /// \brief Returns the stack alignment field of an attribute as a byte 130943c29135e03e55f9a5dab393786171a4a536482Bill Wendling /// alignment value. 131e66f3d3ba0ea9f82f65a29c47fc37e997cbf0aceBill Wendling unsigned getStackAlignment() const; 13230b483c94001927b3593ed200e823104bab51660Bill Wendling 13360507d53e7e8e6b0c537675f68204a93c3033de7Bill Wendling /// \brief Equality and non-equality query methods. 13492e287f5bde8d34af9c3f2979afb6cd05bfb452cBill Wendling bool operator==(AttrKind K) const; 13592e287f5bde8d34af9c3f2979afb6cd05bfb452cBill Wendling bool operator!=(AttrKind K) const; 13692e287f5bde8d34af9c3f2979afb6cd05bfb452cBill Wendling 1372d5be6c313c0f9e23e56620fa8f8ae8d9b539bf0Bill Wendling bool operator==(Attribute A) const { return pImpl == A.pImpl; } 1382d5be6c313c0f9e23e56620fa8f8ae8d9b539bf0Bill Wendling bool operator!=(Attribute A) const { return pImpl != A.pImpl; } 1392d5be6c313c0f9e23e56620fa8f8ae8d9b539bf0Bill Wendling 140c08a5ef6581f2c7550e92d31f63cd65ec29c39e0Bill Wendling /// \brief Less-than operator. Useful for sorting the attributes list. 1413467e30edf63b6d8a8d446186674ba9e4b7885a9Bill Wendling bool operator<(Attribute A) const; 1423467e30edf63b6d8a8d446186674ba9e4b7885a9Bill Wendling 143c08a5ef6581f2c7550e92d31f63cd65ec29c39e0Bill Wendling /// \brief The Attribute is converted to a string of equivalent mnemonic. This 144c08a5ef6581f2c7550e92d31f63cd65ec29c39e0Bill Wendling /// is, presumably, for writing out the mnemonics for the assembly writer. 145c08a5ef6581f2c7550e92d31f63cd65ec29c39e0Bill Wendling std::string getAsString() const; 146c08a5ef6581f2c7550e92d31f63cd65ec29c39e0Bill Wendling 147bb08593980b16fbd9758da6ca4fa9c7964f2f926Bill Wendling void Profile(FoldingSetNodeID &ID) const { 148bb08593980b16fbd9758da6ca4fa9c7964f2f926Bill Wendling ID.AddPointer(pImpl); 149bb08593980b16fbd9758da6ca4fa9c7964f2f926Bill Wendling } 1503467e30edf63b6d8a8d446186674ba9e4b7885a9Bill Wendling 1511db9b6957c2565a2322206bd5907530895f1c7acBill Wendling uint64_t Raw() const; 152827cde1c8319e51463007078a7ce3660ebc93036Duncan Sands}; 153827cde1c8319e51463007078a7ce3660ebc93036Duncan Sands 154e66f3d3ba0ea9f82f65a29c47fc37e997cbf0aceBill Wendling//===----------------------------------------------------------------------===// 15527107f6ab4627fa38bcacad6757ed6d52910f880Bill Wendling/// \class 1560319888773b36dd61d7d2283cb9a26cac1e5abe8Bill Wendling/// \brief Provide DenseMapInfo for Attribute::AttrKinds. This is used by 1570319888773b36dd61d7d2283cb9a26cac1e5abe8Bill Wendling/// AttrBuilder. 1580319888773b36dd61d7d2283cb9a26cac1e5abe8Bill Wendlingtemplate<> struct DenseMapInfo<Attribute::AttrKind> { 1590319888773b36dd61d7d2283cb9a26cac1e5abe8Bill Wendling static inline Attribute::AttrKind getEmptyKey() { 1606f78fbbc630d2b86fb752574f5ad74473f57dfb1Chandler Carruth return Attribute::AttrKindEmptyKey; 1610319888773b36dd61d7d2283cb9a26cac1e5abe8Bill Wendling } 1620319888773b36dd61d7d2283cb9a26cac1e5abe8Bill Wendling static inline Attribute::AttrKind getTombstoneKey() { 1636f78fbbc630d2b86fb752574f5ad74473f57dfb1Chandler Carruth return Attribute::AttrKindTombstoneKey; 1640319888773b36dd61d7d2283cb9a26cac1e5abe8Bill Wendling } 1650319888773b36dd61d7d2283cb9a26cac1e5abe8Bill Wendling static unsigned getHashValue(const Attribute::AttrKind &Val) { 1660319888773b36dd61d7d2283cb9a26cac1e5abe8Bill Wendling return Val * 37U; 1670319888773b36dd61d7d2283cb9a26cac1e5abe8Bill Wendling } 1680319888773b36dd61d7d2283cb9a26cac1e5abe8Bill Wendling static bool isEqual(const Attribute::AttrKind &LHS, 1690319888773b36dd61d7d2283cb9a26cac1e5abe8Bill Wendling const Attribute::AttrKind &RHS) { 1700319888773b36dd61d7d2283cb9a26cac1e5abe8Bill Wendling return LHS == RHS; 1710319888773b36dd61d7d2283cb9a26cac1e5abe8Bill Wendling } 1720319888773b36dd61d7d2283cb9a26cac1e5abe8Bill Wendling}; 1730319888773b36dd61d7d2283cb9a26cac1e5abe8Bill Wendling 1740319888773b36dd61d7d2283cb9a26cac1e5abe8Bill Wendling//===----------------------------------------------------------------------===// 17599faa3b4ec6d03ac7808fe4ff3fbf3d04e375502Bill Wendling// AttributeSet Smart Pointer 17658d74910c6b82e622ecbb57d6644d48fec5a5c0fChris Lattner//===----------------------------------------------------------------------===// 17758d74910c6b82e622ecbb57d6644d48fec5a5c0fChris Lattner 178a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendlingclass AttrBuilder; 17918e7211068c9d2c6204512f9c468ee179818a4b6Bill Wendlingclass AttributeSetImpl; 18008c11d302325b3715d77f4208d183c9b2a253b14Bill Wendling 18108c11d302325b3715d77f4208d183c9b2a253b14Bill Wendling//===----------------------------------------------------------------------===// 18208c11d302325b3715d77f4208d183c9b2a253b14Bill Wendling/// \class 18308c11d302325b3715d77f4208d183c9b2a253b14Bill Wendling/// \brief This is just a pair of values to associate a set of attributes with 18408c11d302325b3715d77f4208d183c9b2a253b14Bill Wendling/// an index. 18508c11d302325b3715d77f4208d183c9b2a253b14Bill Wendlingstruct AttributeWithIndex { 18608c11d302325b3715d77f4208d183c9b2a253b14Bill Wendling Attribute Attrs; ///< The attributes that are set, or'd together. 18708c11d302325b3715d77f4208d183c9b2a253b14Bill Wendling unsigned Index; ///< Index of the parameter for which the attributes apply. 18808c11d302325b3715d77f4208d183c9b2a253b14Bill Wendling 18908c11d302325b3715d77f4208d183c9b2a253b14Bill Wendling static AttributeWithIndex get(unsigned Idx, Attribute Attrs) { 19008c11d302325b3715d77f4208d183c9b2a253b14Bill Wendling AttributeWithIndex P; 19108c11d302325b3715d77f4208d183c9b2a253b14Bill Wendling P.Index = Idx; 19208c11d302325b3715d77f4208d183c9b2a253b14Bill Wendling P.Attrs = Attrs; 19308c11d302325b3715d77f4208d183c9b2a253b14Bill Wendling return P; 19408c11d302325b3715d77f4208d183c9b2a253b14Bill Wendling } 19508c11d302325b3715d77f4208d183c9b2a253b14Bill Wendling}; 196710632d07b13609444626367bebd34c0af3acb6aMikhail Glushenkov 19718e7211068c9d2c6204512f9c468ee179818a4b6Bill Wendling//===----------------------------------------------------------------------===// 19827107f6ab4627fa38bcacad6757ed6d52910f880Bill Wendling/// \class 19927107f6ab4627fa38bcacad6757ed6d52910f880Bill Wendling/// \brief This class manages the ref count for the opaque AttributeSetImpl 20018e7211068c9d2c6204512f9c468ee179818a4b6Bill Wendling/// object and provides accessors for it. 20199faa3b4ec6d03ac7808fe4ff3fbf3d04e375502Bill Wendlingclass AttributeSet { 20207aae2e7d58fe23e370e0cbb9e1a3def99434c36Bill Wendlingpublic: 20307aae2e7d58fe23e370e0cbb9e1a3def99434c36Bill Wendling enum AttrIndex { 20407aae2e7d58fe23e370e0cbb9e1a3def99434c36Bill Wendling ReturnIndex = 0U, 20507aae2e7d58fe23e370e0cbb9e1a3def99434c36Bill Wendling FunctionIndex = ~0U 20607aae2e7d58fe23e370e0cbb9e1a3def99434c36Bill Wendling }; 20707aae2e7d58fe23e370e0cbb9e1a3def99434c36Bill Wendlingprivate: 208a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling friend class AttrBuilder; 2097d38c109aab8654e63e9071c7d948661f6b58433Bill Wendling friend class AttributeSetImpl; 210a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling 21118e7211068c9d2c6204512f9c468ee179818a4b6Bill Wendling /// \brief The attributes that we are managing. This can be null to represent 2120976e00fd1cbf4128daeb72efd8957d00383fda9Bill Wendling /// the empty attributes list. 213ec2589863b32da169240c4fa120ef1e3798615d4Bill Wendling AttributeSetImpl *pImpl; 2140976e00fd1cbf4128daeb72efd8957d00383fda9Bill Wendling 21518e7211068c9d2c6204512f9c468ee179818a4b6Bill Wendling /// \brief The attributes for the specified index are returned. Attributes 2160976e00fd1cbf4128daeb72efd8957d00383fda9Bill Wendling /// for the result are denoted with Idx = 0. 21753ff78b2019e96e142986d19dd99f8dd563dc494NAKAMURA Takumi Attribute getAttributes(unsigned Idx) const; 2180976e00fd1cbf4128daeb72efd8957d00383fda9Bill Wendling 219defaca00b8087d452df2b783250a48a32658a910Bill Wendling /// \brief Add the specified attribute at the specified index to this 220defaca00b8087d452df2b783250a48a32658a910Bill Wendling /// attribute list. Since attribute lists are immutable, this returns the new 221defaca00b8087d452df2b783250a48a32658a910Bill Wendling /// list. 22249f6060f16aec4024d644a6ec4ddd3de9b3e8821Bill Wendling AttributeSet addAttr(LLVMContext &C, unsigned Idx, AttributeSet Attrs) const; 223defaca00b8087d452df2b783250a48a32658a910Bill Wendling 2248246df61f6de716acf1f8c64fac3c19970a2c174Bill Wendling /// \brief Remove the specified attribute at the specified index from this 2258246df61f6de716acf1f8c64fac3c19970a2c174Bill Wendling /// attribute list. Since attribute lists are immutable, this returns the new 2268246df61f6de716acf1f8c64fac3c19970a2c174Bill Wendling /// list. 2278246df61f6de716acf1f8c64fac3c19970a2c174Bill Wendling AttributeSet removeAttr(LLVMContext &C, unsigned Idx, Attribute Attrs) const; 2288246df61f6de716acf1f8c64fac3c19970a2c174Bill Wendling 2297d38c109aab8654e63e9071c7d948661f6b58433Bill Wendling /// \brief Create an AttributeSet from the AttributeWithIndex structures. 2307d38c109aab8654e63e9071c7d948661f6b58433Bill Wendling /// N.B. this is only temporary. It will be disappearing in the future. 2317d38c109aab8654e63e9071c7d948661f6b58433Bill Wendling static AttributeSet get(LLVMContext &C, ArrayRef<AttributeWithIndex> Attrs); 2327d38c109aab8654e63e9071c7d948661f6b58433Bill Wendling 233ec2589863b32da169240c4fa120ef1e3798615d4Bill Wendling explicit AttributeSet(AttributeSetImpl *LI) : pImpl(LI) {} 23458d74910c6b82e622ecbb57d6644d48fec5a5c0fChris Lattnerpublic: 235ec2589863b32da169240c4fa120ef1e3798615d4Bill Wendling AttributeSet() : pImpl(0) {} 236ec2589863b32da169240c4fa120ef1e3798615d4Bill Wendling AttributeSet(const AttributeSet &P) : pImpl(P.pImpl) {} 237d05204aea4977eaec25e96bc7605a7bb9d806fc0Bill Wendling const AttributeSet &operator=(const AttributeSet &RHS) { 238d05204aea4977eaec25e96bc7605a7bb9d806fc0Bill Wendling pImpl = RHS.pImpl; 239d05204aea4977eaec25e96bc7605a7bb9d806fc0Bill Wendling return *this; 240d05204aea4977eaec25e96bc7605a7bb9d806fc0Bill Wendling } 241710632d07b13609444626367bebd34c0af3acb6aMikhail Glushenkov 24258d74910c6b82e622ecbb57d6644d48fec5a5c0fChris Lattner //===--------------------------------------------------------------------===// 2430598866c052147c31b808391f58434ce3dbfb838Devang Patel // Attribute List Construction and Mutation 24458d74910c6b82e622ecbb57d6644d48fec5a5c0fChris Lattner //===--------------------------------------------------------------------===// 245710632d07b13609444626367bebd34c0af3acb6aMikhail Glushenkov 24618e7211068c9d2c6204512f9c468ee179818a4b6Bill Wendling /// \brief Return an AttributeSet with the specified parameters in it. 2478e47daf2858e980210f3e1f007036b24da342c29Bill Wendling static AttributeSet get(LLVMContext &C, ArrayRef<AttributeSet> Attrs); 24828d65722d6f283b327b5815914382077fe9c0ab4Bill Wendling static AttributeSet get(LLVMContext &C, unsigned Idx, 24932a57958226e369f964a034da2ce7083a1a34297Bill Wendling ArrayRef<Attribute::AttrKind> Kind); 2501bbd644301ed4d8a7efd4ceb15f71c56fa914f28Bill Wendling static AttributeSet get(LLVMContext &C, unsigned Idx, AttrBuilder &B); 25158d74910c6b82e622ecbb57d6644d48fec5a5c0fChris Lattner 252defaca00b8087d452df2b783250a48a32658a910Bill Wendling /// \brief Add an attribute to the attribute set at the given index. Since 253defaca00b8087d452df2b783250a48a32658a910Bill Wendling /// attribute sets are immutable, this returns a new set. 254defaca00b8087d452df2b783250a48a32658a910Bill Wendling AttributeSet addAttribute(LLVMContext &C, unsigned Idx, 255defaca00b8087d452df2b783250a48a32658a910Bill Wendling Attribute::AttrKind Attr) const; 256710632d07b13609444626367bebd34c0af3acb6aMikhail Glushenkov 257e4e85f17564c28cd571dda30146c3f310521acf0Bill Wendling /// \brief Add attributes to the attribute set at the given index. Since 258e4e85f17564c28cd571dda30146c3f310521acf0Bill Wendling /// attribute sets are immutable, this returns a new set. 259e4e85f17564c28cd571dda30146c3f310521acf0Bill Wendling AttributeSet addAttributes(LLVMContext &C, unsigned Idx, 260e4e85f17564c28cd571dda30146c3f310521acf0Bill Wendling AttributeSet Attrs) const; 261e4e85f17564c28cd571dda30146c3f310521acf0Bill Wendling 2621b0c54f1c5dd61e56cb7cbc435fcb3319cff628fBill Wendling /// \brief Add return attributes to this attribute set. Since attribute sets 2631b0c54f1c5dd61e56cb7cbc435fcb3319cff628fBill Wendling /// are immutable, this returns a new set. 264e4e85f17564c28cd571dda30146c3f310521acf0Bill Wendling AttributeSet addRetAttributes(LLVMContext &C, AttributeSet Attrs) const { 265e4e85f17564c28cd571dda30146c3f310521acf0Bill Wendling return addAttributes(C, ReturnIndex, Attrs); 266e4e85f17564c28cd571dda30146c3f310521acf0Bill Wendling } 2671b0c54f1c5dd61e56cb7cbc435fcb3319cff628fBill Wendling 268956f13440a4aa0297606a4412f4aa091d931592aBill Wendling /// \brief Add function attributes to this attribute set. Since attribute sets 269956f13440a4aa0297606a4412f4aa091d931592aBill Wendling /// are immutable, this returns a new set. 270e4e85f17564c28cd571dda30146c3f310521acf0Bill Wendling AttributeSet addFnAttributes(LLVMContext &C, AttributeSet Attrs) const { 271e4e85f17564c28cd571dda30146c3f310521acf0Bill Wendling return addAttributes(C, FunctionIndex, Attrs); 272e4e85f17564c28cd571dda30146c3f310521acf0Bill Wendling } 273956f13440a4aa0297606a4412f4aa091d931592aBill Wendling 27418e7211068c9d2c6204512f9c468ee179818a4b6Bill Wendling /// \brief Remove the specified attribute at the specified index from this 2758246df61f6de716acf1f8c64fac3c19970a2c174Bill Wendling /// attribute list. Since attribute lists are immutable, this returns the new 27618e7211068c9d2c6204512f9c468ee179818a4b6Bill Wendling /// list. 2778246df61f6de716acf1f8c64fac3c19970a2c174Bill Wendling AttributeSet removeAttribute(LLVMContext &C, unsigned Idx, 2788246df61f6de716acf1f8c64fac3c19970a2c174Bill Wendling Attribute::AttrKind Attr) const; 2798246df61f6de716acf1f8c64fac3c19970a2c174Bill Wendling 2808246df61f6de716acf1f8c64fac3c19970a2c174Bill Wendling /// \brief Remove the specified attributes at the specified index from this 2818246df61f6de716acf1f8c64fac3c19970a2c174Bill Wendling /// attribute list. Since attribute lists are immutable, this returns the new 2828246df61f6de716acf1f8c64fac3c19970a2c174Bill Wendling /// list. 2838246df61f6de716acf1f8c64fac3c19970a2c174Bill Wendling AttributeSet removeAttributes(LLVMContext &C, unsigned Idx, 2848246df61f6de716acf1f8c64fac3c19970a2c174Bill Wendling AttributeSet Attrs) const; 285710632d07b13609444626367bebd34c0af3acb6aMikhail Glushenkov 28658d74910c6b82e622ecbb57d6644d48fec5a5c0fChris Lattner //===--------------------------------------------------------------------===// 28749f6060f16aec4024d644a6ec4ddd3de9b3e8821Bill Wendling // Attribute Set Accessors 28858d74910c6b82e622ecbb57d6644d48fec5a5c0fChris Lattner //===--------------------------------------------------------------------===// 28918e7211068c9d2c6204512f9c468ee179818a4b6Bill Wendling 29018e7211068c9d2c6204512f9c468ee179818a4b6Bill Wendling /// \brief The attributes for the specified index are returned. 29128d65722d6f283b327b5815914382077fe9c0ab4Bill Wendling AttributeSet getParamAttributes(unsigned Idx) const; 29219c874638d9478a5d5028854817a5ee72293bb2bDevang Patel 29318e7211068c9d2c6204512f9c468ee179818a4b6Bill Wendling /// \brief The attributes for the ret value are returned. 2943fc4b96b503fa202411317684a2ba02e41e43072Bill Wendling AttributeSet getRetAttributes() const; 29519c874638d9478a5d5028854817a5ee72293bb2bDevang Patel 29618e7211068c9d2c6204512f9c468ee179818a4b6Bill Wendling /// \brief The function attributes are returned. 297c5f1bc88a2eb7ad9ff924ca90cf88494e5f947b9Bill Wendling AttributeSet getFnAttributes() const; 298710632d07b13609444626367bebd34c0af3acb6aMikhail Glushenkov 299831737d329a727f53a1fb0572f7b7a8127208881Bill Wendling /// \brief Return true if the attribute exists at the given index. 30049f6060f16aec4024d644a6ec4ddd3de9b3e8821Bill Wendling bool hasAttribute(uint64_t Index, Attribute::AttrKind Kind) const; 301831737d329a727f53a1fb0572f7b7a8127208881Bill Wendling 302831737d329a727f53a1fb0572f7b7a8127208881Bill Wendling /// \brief Return true if attribute exists at the given index. 30349f6060f16aec4024d644a6ec4ddd3de9b3e8821Bill Wendling bool hasAttributes(uint64_t Index) const; 304831737d329a727f53a1fb0572f7b7a8127208881Bill Wendling 30549f6060f16aec4024d644a6ec4ddd3de9b3e8821Bill Wendling /// \brief Return the alignment for the specified function parameter. 30649f6060f16aec4024d644a6ec4ddd3de9b3e8821Bill Wendling unsigned getParamAlignment(uint64_t Idx) const; 3078e47daf2858e980210f3e1f007036b24da342c29Bill Wendling 308831737d329a727f53a1fb0572f7b7a8127208881Bill Wendling /// \brief Get the stack alignment. 30949f6060f16aec4024d644a6ec4ddd3de9b3e8821Bill Wendling unsigned getStackAlignment(uint64_t Index) const; 310831737d329a727f53a1fb0572f7b7a8127208881Bill Wendling 311831737d329a727f53a1fb0572f7b7a8127208881Bill Wendling /// \brief Return the attributes at the index as a string. 31249f6060f16aec4024d644a6ec4ddd3de9b3e8821Bill Wendling std::string getAsString(uint64_t Index) const; 313831737d329a727f53a1fb0572f7b7a8127208881Bill Wendling 31453ff78b2019e96e142986d19dd99f8dd563dc494NAKAMURA Takumi uint64_t Raw(unsigned Index) const; 315831737d329a727f53a1fb0572f7b7a8127208881Bill Wendling 31618e7211068c9d2c6204512f9c468ee179818a4b6Bill Wendling /// \brief Return true if the specified attribute is set for at least one 31718e7211068c9d2c6204512f9c468ee179818a4b6Bill Wendling /// parameter or for the return value. 318629fb82419d9bfff6ae475363bcce66192dfcc8eBill Wendling bool hasAttrSomewhere(Attribute::AttrKind Attr) const; 31958d74910c6b82e622ecbb57d6644d48fec5a5c0fChris Lattner 320041221c0972ff575b07f76808c504833d629ae1fChris Lattner /// operator==/!= - Provide equality predicates. 32118e7211068c9d2c6204512f9c468ee179818a4b6Bill Wendling bool operator==(const AttributeSet &RHS) const { 322ec2589863b32da169240c4fa120ef1e3798615d4Bill Wendling return pImpl == RHS.pImpl; 32318e7211068c9d2c6204512f9c468ee179818a4b6Bill Wendling } 32418e7211068c9d2c6204512f9c468ee179818a4b6Bill Wendling bool operator!=(const AttributeSet &RHS) const { 325ec2589863b32da169240c4fa120ef1e3798615d4Bill Wendling return pImpl != RHS.pImpl; 32618e7211068c9d2c6204512f9c468ee179818a4b6Bill Wendling } 327710632d07b13609444626367bebd34c0af3acb6aMikhail Glushenkov 32858d74910c6b82e622ecbb57d6644d48fec5a5c0fChris Lattner //===--------------------------------------------------------------------===// 3290598866c052147c31b808391f58434ce3dbfb838Devang Patel // Attribute List Introspection 33058d74910c6b82e622ecbb57d6644d48fec5a5c0fChris Lattner //===--------------------------------------------------------------------===// 331710632d07b13609444626367bebd34c0af3acb6aMikhail Glushenkov 33218e7211068c9d2c6204512f9c468ee179818a4b6Bill Wendling /// \brief Return a raw pointer that uniquely identifies this attribute list. 33358d74910c6b82e622ecbb57d6644d48fec5a5c0fChris Lattner void *getRawPointer() const { 334ec2589863b32da169240c4fa120ef1e3798615d4Bill Wendling return pImpl; 33558d74910c6b82e622ecbb57d6644d48fec5a5c0fChris Lattner } 336710632d07b13609444626367bebd34c0af3acb6aMikhail Glushenkov 337034b94b17006f51722886b0f2283fb6fb19aca1fBill Wendling // Attributes are stored as a dense set of slots, where there is one slot for 338034b94b17006f51722886b0f2283fb6fb19aca1fBill Wendling // each argument that has an attribute. This allows walking over the dense 339034b94b17006f51722886b0f2283fb6fb19aca1fBill Wendling // set instead of walking the sparse list of attributes. 340710632d07b13609444626367bebd34c0af3acb6aMikhail Glushenkov 34118e7211068c9d2c6204512f9c468ee179818a4b6Bill Wendling /// \brief Return true if there are no attributes. 34258d74910c6b82e622ecbb57d6644d48fec5a5c0fChris Lattner bool isEmpty() const { 343ec2589863b32da169240c4fa120ef1e3798615d4Bill Wendling return pImpl == 0; 34458d74910c6b82e622ecbb57d6644d48fec5a5c0fChris Lattner } 345710632d07b13609444626367bebd34c0af3acb6aMikhail Glushenkov 34618e7211068c9d2c6204512f9c468ee179818a4b6Bill Wendling /// \brief Return the number of slots used in this attribute list. This is 34718e7211068c9d2c6204512f9c468ee179818a4b6Bill Wendling /// the number of arguments that have an attribute set on them (including the 34818e7211068c9d2c6204512f9c468ee179818a4b6Bill Wendling /// function itself). 34958d74910c6b82e622ecbb57d6644d48fec5a5c0fChris Lattner unsigned getNumSlots() const; 350710632d07b13609444626367bebd34c0af3acb6aMikhail Glushenkov 351e1f95db4803a48a30fc2a1d5868281a87a36fb85Bill Wendling /// \brief Return the index for the given slot. 3523e3e789aede6ec38d39c95d88ad4e8634d5a259bBill Wendling uint64_t getSlotIndex(unsigned Slot) const; 353e1f95db4803a48a30fc2a1d5868281a87a36fb85Bill Wendling 3548e47daf2858e980210f3e1f007036b24da342c29Bill Wendling /// \brief Return the attributes at the given slot. 3558e47daf2858e980210f3e1f007036b24da342c29Bill Wendling AttributeSet getSlotAttributes(unsigned Slot) const; 3568e47daf2858e980210f3e1f007036b24da342c29Bill Wendling 357f3d1500ab2c7364d3d0fb73a7e1b8c6339ab48b1Bill Wendling void dump() const; 35858d74910c6b82e622ecbb57d6644d48fec5a5c0fChris Lattner}; 3594f859aa532dbf061736f9c23e0d0882b5cdfe566Reid Spencer 360a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling//===----------------------------------------------------------------------===// 361a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling/// \class 362a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling/// \brief This class is used in conjunction with the Attribute::get method to 363a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling/// create an Attribute object. The object itself is uniquified. The Builder's 364a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling/// value, however, is not. So this can be used as a quick way to test for 365a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling/// equality, presence of attributes, etc. 366a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendlingclass AttrBuilder { 367a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling DenseSet<Attribute::AttrKind> Attrs; 368a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling uint64_t Alignment; 369a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling uint64_t StackAlignment; 370a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendlingpublic: 371a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling AttrBuilder() : Alignment(0), StackAlignment(0) {} 372a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling explicit AttrBuilder(uint64_t B) : Alignment(0), StackAlignment(0) { 373a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling addRawValue(B); 374a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling } 375a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling AttrBuilder(const Attribute &A) : Alignment(0), StackAlignment(0) { 376a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling addAttributes(A); 377a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling } 378a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling AttrBuilder(AttributeSet AS, unsigned Idx); 379a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling 380a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling void clear(); 381a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling 382a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling /// \brief Add an attribute to the builder. 383a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling AttrBuilder &addAttribute(Attribute::AttrKind Val); 384a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling 385a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling /// \brief Remove an attribute from the builder. 386a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling AttrBuilder &removeAttribute(Attribute::AttrKind Val); 387a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling 38849f6060f16aec4024d644a6ec4ddd3de9b3e8821Bill Wendling /// \brief Add the attributes to the builder. 38949f6060f16aec4024d644a6ec4ddd3de9b3e8821Bill Wendling AttrBuilder &addAttributes(Attribute A); 39049f6060f16aec4024d644a6ec4ddd3de9b3e8821Bill Wendling 39149f6060f16aec4024d644a6ec4ddd3de9b3e8821Bill Wendling /// \brief Remove the attributes from the builder. 39249f6060f16aec4024d644a6ec4ddd3de9b3e8821Bill Wendling AttrBuilder &removeAttributes(Attribute A); 393a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling 39449f6060f16aec4024d644a6ec4ddd3de9b3e8821Bill Wendling /// \brief Add the attributes to the builder. 39549f6060f16aec4024d644a6ec4ddd3de9b3e8821Bill Wendling AttrBuilder &addAttributes(AttributeSet A); 396a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling 397a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling /// \brief Return true if the builder has the specified attribute. 398a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling bool contains(Attribute::AttrKind A) const; 399a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling 400a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling /// \brief Return true if the builder has IR-level attributes. 401a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling bool hasAttributes() const; 402a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling 403a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling /// \brief Return true if the builder has any attribute that's in the 404a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling /// specified attribute. 405a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling bool hasAttributes(const Attribute &A) const; 406a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling 407a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling /// \brief Return true if the builder has an alignment attribute. 408a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling bool hasAlignmentAttr() const; 409a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling 410a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling /// \brief Retrieve the alignment attribute, if it exists. 411a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling uint64_t getAlignment() const { return Alignment; } 412a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling 413a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling /// \brief Retrieve the stack alignment attribute, if it exists. 414a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling uint64_t getStackAlignment() const { return StackAlignment; } 415a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling 416a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling /// \brief This turns an int alignment (which must be a power of 2) into the 417a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling /// form used internally in Attribute. 418a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling AttrBuilder &addAlignmentAttr(unsigned Align); 419a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling 420a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling /// \brief This turns an int stack alignment (which must be a power of 2) into 421a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling /// the form used internally in Attribute. 422a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling AttrBuilder &addStackAlignmentAttr(unsigned Align); 423a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling 424a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling typedef DenseSet<Attribute::AttrKind>::iterator iterator; 425a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling typedef DenseSet<Attribute::AttrKind>::const_iterator const_iterator; 426a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling 427a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling iterator begin() { return Attrs.begin(); } 428a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling iterator end() { return Attrs.end(); } 429a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling 430a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling const_iterator begin() const { return Attrs.begin(); } 431a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling const_iterator end() const { return Attrs.end(); } 432a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling 433a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling /// \brief Add the raw value to the internal representation. 434a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling /// 435a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling /// N.B. This should be used ONLY for decoding LLVM bitcode! 436a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling AttrBuilder &addRawValue(uint64_t Val); 437a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling 438a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling /// \brief Remove attributes that are used on functions only. 439a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling void removeFunctionOnlyAttrs() { 440a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling removeAttribute(Attribute::NoReturn) 441a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling .removeAttribute(Attribute::NoUnwind) 442a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling .removeAttribute(Attribute::ReadNone) 443a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling .removeAttribute(Attribute::ReadOnly) 444a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling .removeAttribute(Attribute::NoInline) 445a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling .removeAttribute(Attribute::AlwaysInline) 446a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling .removeAttribute(Attribute::OptimizeForSize) 447a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling .removeAttribute(Attribute::StackProtect) 448a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling .removeAttribute(Attribute::StackProtectReq) 449114baee1fa017daefad2339c77b45b9ca3d79a41Bill Wendling .removeAttribute(Attribute::StackProtectStrong) 450a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling .removeAttribute(Attribute::NoRedZone) 451a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling .removeAttribute(Attribute::NoImplicitFloat) 452a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling .removeAttribute(Attribute::Naked) 453a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling .removeAttribute(Attribute::InlineHint) 454a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling .removeAttribute(Attribute::StackAlignment) 455a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling .removeAttribute(Attribute::UWTable) 456a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling .removeAttribute(Attribute::NonLazyBind) 457a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling .removeAttribute(Attribute::ReturnsTwice) 458a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling .removeAttribute(Attribute::AddressSafety) 459a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling .removeAttribute(Attribute::MinSize) 460a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling .removeAttribute(Attribute::NoDuplicate); 461a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling } 462a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling 4631db9b6957c2565a2322206bd5907530895f1c7acBill Wendling uint64_t Raw() const; 464a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling 465a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling bool operator==(const AttrBuilder &B); 466a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling bool operator!=(const AttrBuilder &B) { 467a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling return !(*this == B); 468a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling } 469a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling}; 470a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling 4718e47daf2858e980210f3e1f007036b24da342c29Bill Wendlingnamespace AttributeFuncs { 4728e47daf2858e980210f3e1f007036b24da342c29Bill Wendling 4738e47daf2858e980210f3e1f007036b24da342c29Bill Wendling/// \brief Which attributes cannot be applied to a type. 4748e47daf2858e980210f3e1f007036b24da342c29Bill WendlingAttribute typeIncompatible(Type *Ty); 4758e47daf2858e980210f3e1f007036b24da342c29Bill Wendling 4768e47daf2858e980210f3e1f007036b24da342c29Bill Wendling/// \brief This returns an integer containing an encoding of all the LLVM 4778e47daf2858e980210f3e1f007036b24da342c29Bill Wendling/// attributes found in the given attribute bitset. Any change to this encoding 4788e47daf2858e980210f3e1f007036b24da342c29Bill Wendling/// is a breaking change to bitcode compatibility. 4798e47daf2858e980210f3e1f007036b24da342c29Bill Wendlinguint64_t encodeLLVMAttributesForBitcode(AttributeSet Attrs, unsigned Index); 4808e47daf2858e980210f3e1f007036b24da342c29Bill Wendling 4818e47daf2858e980210f3e1f007036b24da342c29Bill Wendling/// \brief This returns an attribute bitset containing the LLVM attributes that 4828e47daf2858e980210f3e1f007036b24da342c29Bill Wendling/// have been decoded from the given integer. This function must stay in sync 4838e47daf2858e980210f3e1f007036b24da342c29Bill Wendling/// with 'encodeLLVMAttributesForBitcode'. 4848e47daf2858e980210f3e1f007036b24da342c29Bill WendlingAttribute decodeLLVMAttributesForBitcode(LLVMContext &C, 4858e47daf2858e980210f3e1f007036b24da342c29Bill Wendling uint64_t EncodedAttrs); 4868e47daf2858e980210f3e1f007036b24da342c29Bill Wendling 4878e47daf2858e980210f3e1f007036b24da342c29Bill Wendling} // end AttributeFuncs namespace 4888e47daf2858e980210f3e1f007036b24da342c29Bill Wendling 48927107f6ab4627fa38bcacad6757ed6d52910f880Bill Wendling} // end llvm namespace 4906091ebd172a16a10f1ea66061a5fa7cbf5139e56Reid Spencer 4916091ebd172a16a10f1ea66061a5fa7cbf5139e56Reid Spencer#endif 492