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" 203467e30edf63b6d8a8d446186674ba9e4b7885a9Bill Wendling#include "llvm/ADT/FoldingSet.h" 21118a0659ab8a4d0e0af343b88e5fa71a5c1eb6a6Reid Kleckner#include "llvm/Support/Compiler.h" 22c835b8c30127d15599de2d614434d39a6cc3ae17Benjamin Kramer#include "llvm/Support/PointerLikeTypeTraits.h" 233f213e7b3a6829a154d4e8ceb7d8689b389bd5dcBenjamin Kramer#include <bitset> 2422bd64173981bf1251c4b3bfc684207340534ba3Bill Wendling#include <cassert> 25ea59f896a672c2e1ef9f02277bce60257aa60989Bill Wendling#include <map> 2658d74910c6b82e622ecbb57d6644d48fec5a5c0fChris Lattner#include <string> 276091ebd172a16a10f1ea66061a5fa7cbf5139e56Reid Spencer 286091ebd172a16a10f1ea66061a5fa7cbf5139e56Reid Spencernamespace llvm { 29d426a642a23a234547cbc7061f5bfec157673249Bill Wendling 30702cc91aa1bd41540e8674921ae7ac89a4ff061fBill Wendlingclass AttrBuilder; 31f6670729aabc1fab85238d2b306a1c1767a807bbBill Wendlingclass AttributeImpl; 32817abdd8b055059e5930a15704b9f52da4236456Bill Wendlingclass AttributeSetImpl; 33817abdd8b055059e5930a15704b9f52da4236456Bill Wendlingclass AttributeSetNode; 346dc3781d44e56f0addf28b06232a50f3f9e6b1afBill Wendlingclass Constant; 35c835b8c30127d15599de2d614434d39a6cc3ae17Benjamin Kramertemplate<typename T> struct DenseMapInfo; 362c79ecbd704c656178ffa43d5a58ebe3ca188b40Bill Wendlingclass LLVMContext; 37ad9a9e15595bc9d5ba1ed752caf8572957f77a3dDuncan Sandsclass Type; 38ad9a9e15595bc9d5ba1ed752caf8572957f77a3dDuncan Sands 391d3dcfe4246b4d45fa78a8dfd0a11c7fff842c15Bill Wendling//===----------------------------------------------------------------------===// 4027107f6ab4627fa38bcacad6757ed6d52910f880Bill Wendling/// \class 4127107f6ab4627fa38bcacad6757ed6d52910f880Bill Wendling/// \brief Functions, function parameters, and return types can have attributes 421d3dcfe4246b4d45fa78a8dfd0a11c7fff842c15Bill Wendling/// to indicate how they should be treated by optimizations and code 431d3dcfe4246b4d45fa78a8dfd0a11c7fff842c15Bill Wendling/// generation. This class represents one of those attributes. It's light-weight 441d3dcfe4246b4d45fa78a8dfd0a11c7fff842c15Bill Wendling/// and should be passed around by-value. 45034b94b17006f51722886b0f2283fb6fb19aca1fBill Wendlingclass Attribute { 466765834754cbb3cb0f15b4b15e98c5e73fa50066Bill Wendlingpublic: 471d3dcfe4246b4d45fa78a8dfd0a11c7fff842c15Bill Wendling /// This enumeration lists the attributes that can be associated with 4873dee180c836270644dfa7d90f9c5ba877567999Bill Wendling /// parameters, function results, or the function itself. 49f3d1500ab2c7364d3d0fb73a7e1b8c6339ab48b1Bill Wendling /// 5073dee180c836270644dfa7d90f9c5ba877567999Bill Wendling /// Note: The `uwtable' attribute is about the ABI or the user mandating an 5173dee180c836270644dfa7d90f9c5ba877567999Bill Wendling /// entry in the unwind table. The `nounwind' attribute is about an exception 5273dee180c836270644dfa7d90f9c5ba877567999Bill Wendling /// passing by the function. 53f3d1500ab2c7364d3d0fb73a7e1b8c6339ab48b1Bill Wendling /// 5473dee180c836270644dfa7d90f9c5ba877567999Bill Wendling /// In a theoretical system that uses tables for profiling and SjLj for 5511d00420e42ba88c3b48cab997965a7be79315e2Bill Wendling /// exceptions, they would be fully independent. In a normal system that uses 5611d00420e42ba88c3b48cab997965a7be79315e2Bill Wendling /// tables for both, the semantics are: 57f3d1500ab2c7364d3d0fb73a7e1b8c6339ab48b1Bill Wendling /// 5811d00420e42ba88c3b48cab997965a7be79315e2Bill Wendling /// nil = Needs an entry because an exception might pass by. 5911d00420e42ba88c3b48cab997965a7be79315e2Bill Wendling /// nounwind = No need for an entry 6011d00420e42ba88c3b48cab997965a7be79315e2Bill Wendling /// uwtable = Needs an entry because the ABI says so and because 6111d00420e42ba88c3b48cab997965a7be79315e2Bill Wendling /// an exception might pass by. 6211d00420e42ba88c3b48cab997965a7be79315e2Bill Wendling /// uwtable + nounwind = Needs an entry because the ABI says so. 6311d00420e42ba88c3b48cab997965a7be79315e2Bill Wendling 64629fb82419d9bfff6ae475363bcce66192dfcc8eBill Wendling enum AttrKind { 655a0eeb5a9d727940b1dbe8dff6e9aa292ada0f6aBill Wendling // IR-Level Attributes 66480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling None, ///< No attributes have been set 67480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling Alignment, ///< Alignment of parameter (5 bits) 686765834754cbb3cb0f15b4b15e98c5e73fa50066Bill Wendling ///< stored as log2 of alignment with +1 bias 69f6670729aabc1fab85238d2b306a1c1767a807bbBill Wendling ///< 0 means unaligned (different from align(1)) 70480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling AlwaysInline, ///< inline=always 712253a2f52f3c46ae75cd05f5885acb987bd1d6b6Michael Gottesman Builtin, ///< Callee is recognized as a builtin, despite 722253a2f52f3c46ae75cd05f5885acb987bd1d6b6Michael Gottesman ///< nobuiltin attribute on its declaration. 73480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling ByVal, ///< Pass structure by value 7436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines InAlloca, ///< Pass structure in an alloca 7577226a03dca98e6237c1068f2652fe41bea7b687Diego Novillo Cold, ///< Marks function as being in a cold path. 76480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling InlineHint, ///< Source said inlining was desirable 77480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling InReg, ///< Force argument to be passed in register 78cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines JumpTable, ///< Build jump-instruction tables and replace refs. 799a419f656e278b96e9dfe739cd63c7bff9a4e1fdQuentin Colombet MinSize, ///< Function must be optimized for size first 80480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling Naked, ///< Naked function 81480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling Nest, ///< Nested function static chain 82480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling NoAlias, ///< Considered to not alias after call 83143d46476cdcf5b88b9ee18ebd799e5820a2db0eBill Wendling NoBuiltin, ///< Callee isn't recognized as a builtin 84480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling NoCapture, ///< Function creates no aliases of pointer 8567ae13575900e8efd056672987249fd0adbf5e73James Molloy NoDuplicate, ///< Call cannot be duplicated 86480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling NoImplicitFloat, ///< Disable implicit floating point insts 87480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling NoInline, ///< inline=never 88480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling NonLazyBind, ///< Function is called early and/or 893a106e60366a51b4594ec303ff8dbbc58913227fBill Wendling ///< often, so lazy binding isn't worthwhile 90dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines NonNull, ///< Pointer is known to be not null 91480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling NoRedZone, ///< Disable redzone 92480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling NoReturn, ///< Mark the function as not returning 93480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling NoUnwind, ///< Function doesn't unwind stack 94480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling OptimizeForSize, ///< opt_size 955768bb8d77892926dff0d078b1fb08c14ea791f3Andrea Di Biagio OptimizeNone, ///< Function must not be optimized. 96480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling ReadNone, ///< Function does not access memory 97480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling ReadOnly, ///< Function only reads from memory 98456ca048af35163b9f52187e92a23ee0a9f059e8Stephen Lin Returned, ///< Return value is always equal to this argument 99480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling ReturnsTwice, ///< Function can return twice 100480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling SExt, ///< Sign extended before/after call 101480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling StackAlignment, ///< Alignment of stack for function (3 bits) 1026765834754cbb3cb0f15b4b15e98c5e73fa50066Bill Wendling ///< stored as log2 of alignment with +1 bias 0 1036765834754cbb3cb0f15b4b15e98c5e73fa50066Bill Wendling ///< means unaligned (different from 104f6670729aabc1fab85238d2b306a1c1767a807bbBill Wendling ///< alignstack=(1)) 105480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling StackProtect, ///< Stack protection. 106480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling StackProtectReq, ///< Stack protection required. 107114baee1fa017daefad2339c77b45b9ca3d79a41Bill Wendling StackProtectStrong, ///< Strong Stack protection. 108480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling StructRet, ///< Hidden pointer to structure to return 1098eec41fc778e99d42172a7f6de76faa43a6d8847Kostya Serebryany SanitizeAddress, ///< AddressSanitizer is on. 1108eec41fc778e99d42172a7f6de76faa43a6d8847Kostya Serebryany SanitizeThread, ///< ThreadSanitizer is on. 1118eec41fc778e99d42172a7f6de76faa43a6d8847Kostya Serebryany SanitizeMemory, ///< MemorySanitizer is on. 112480b1b28ea6fc1bb5c78d99472df624cfd3fce47Bill Wendling UWTable, ///< Function must be in a unwind table 1130319888773b36dd61d7d2283cb9a26cac1e5abe8Bill Wendling ZExt, ///< Zero extended before/after call 1140319888773b36dd61d7d2283cb9a26cac1e5abe8Bill Wendling 115886a7663c72cb04eaee58cb6997c394f5096a8b9Benjamin Kramer EndAttrKinds ///< Sentinal value useful for loops 1166765834754cbb3cb0f15b4b15e98c5e73fa50066Bill Wendling }; 1176765834754cbb3cb0f15b4b15e98c5e73fa50066Bill Wendlingprivate: 11827107f6ab4627fa38bcacad6757ed6d52910f880Bill Wendling AttributeImpl *pImpl; 11927107f6ab4627fa38bcacad6757ed6d52910f880Bill Wendling Attribute(AttributeImpl *A) : pImpl(A) {} 120d426a642a23a234547cbc7061f5bfec157673249Bill Wendlingpublic: 121dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines Attribute() : pImpl(nullptr) {} 1222c79ecbd704c656178ffa43d5a58ebe3ca188b40Bill Wendling 123c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling //===--------------------------------------------------------------------===// 124c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling // Attribute Construction 125c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling //===--------------------------------------------------------------------===// 126c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling 127c08a5ef6581f2c7550e92d31f63cd65ec29c39e0Bill Wendling /// \brief Return a uniquified Attribute object. 1288c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling static Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val = 0); 1298c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling static Attribute get(LLVMContext &Context, StringRef Kind, 1308c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling StringRef Val = StringRef()); 1312c79ecbd704c656178ffa43d5a58ebe3ca188b40Bill Wendling 132c08a5ef6581f2c7550e92d31f63cd65ec29c39e0Bill Wendling /// \brief Return a uniquified Attribute object that has the specific 133c08a5ef6581f2c7550e92d31f63cd65ec29c39e0Bill Wendling /// alignment set. 134c08a5ef6581f2c7550e92d31f63cd65ec29c39e0Bill Wendling static Attribute getWithAlignment(LLVMContext &Context, uint64_t Align); 135c08a5ef6581f2c7550e92d31f63cd65ec29c39e0Bill Wendling static Attribute getWithStackAlignment(LLVMContext &Context, uint64_t Align); 136c08a5ef6581f2c7550e92d31f63cd65ec29c39e0Bill Wendling 137c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling //===--------------------------------------------------------------------===// 138c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling // Attribute Accessors 139c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling //===--------------------------------------------------------------------===// 140c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling 1418c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling /// \brief Return true if the attribute is an Attribute::AttrKind type. 1428c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling bool isEnumAttribute() const; 1438c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling 1448c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling /// \brief Return true if the attribute is an alignment attribute. 1458c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling bool isAlignAttribute() const; 1468c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling 1478c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling /// \brief Return true if the attribute is a string (target-dependent) 1488c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling /// attribute. 1498c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling bool isStringAttribute() const; 1508c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling 151eddab1550ee10cce3bb26a26e88529cb19451aa3NAKAMURA Takumi /// \brief Return true if the attribute is present. 152eddab1550ee10cce3bb26a26e88529cb19451aa3NAKAMURA Takumi bool hasAttribute(AttrKind Val) const; 153eddab1550ee10cce3bb26a26e88529cb19451aa3NAKAMURA Takumi 15464754f499058b5dc748ea6d06a084af0ed539ec4Bill Wendling /// \brief Return true if the target-dependent attribute is present. 15564754f499058b5dc748ea6d06a084af0ed539ec4Bill Wendling bool hasAttribute(StringRef Val) const; 15664754f499058b5dc748ea6d06a084af0ed539ec4Bill Wendling 1578c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling /// \brief Return the attribute's kind as an enum (Attribute::AttrKind). This 1588c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling /// requires the attribute to be an enum or alignment attribute. 1598c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling Attribute::AttrKind getKindAsEnum() const; 1606dc3781d44e56f0addf28b06232a50f3f9e6b1afBill Wendling 1618c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling /// \brief Return the attribute's value as an integer. This requires that the 1628c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling /// attribute be an alignment attribute. 1638c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling uint64_t getValueAsInt() const; 1648c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling 1658c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling /// \brief Return the attribute's kind as a string. This requires the 1668c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling /// attribute to be a string attribute. 1678c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling StringRef getKindAsString() const; 1688c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling 1698c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling /// \brief Return the attribute's value as a string. This requires the 1708c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling /// attribute to be a string attribute. 1718c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling StringRef getValueAsString() const; 1726dc3781d44e56f0addf28b06232a50f3f9e6b1afBill Wendling 1731d3dcfe4246b4d45fa78a8dfd0a11c7fff842c15Bill Wendling /// \brief Returns the alignment field of an attribute as a byte alignment 174ef99fe8efaa6cb74c66e570a6ef467debca92911Bill Wendling /// value. 175e66f3d3ba0ea9f82f65a29c47fc37e997cbf0aceBill Wendling unsigned getAlignment() const; 176ef99fe8efaa6cb74c66e570a6ef467debca92911Bill Wendling 1771d3dcfe4246b4d45fa78a8dfd0a11c7fff842c15Bill Wendling /// \brief Returns the stack alignment field of an attribute as a byte 178943c29135e03e55f9a5dab393786171a4a536482Bill Wendling /// alignment value. 179e66f3d3ba0ea9f82f65a29c47fc37e997cbf0aceBill Wendling unsigned getStackAlignment() const; 18030b483c94001927b3593ed200e823104bab51660Bill Wendling 181c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling /// \brief The Attribute is converted to a string of equivalent mnemonic. This 182c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling /// is, presumably, for writing out the mnemonics for the assembly writer. 183b29ce26ea60f7516c853318ffbfc107fde9ad897Bill Wendling std::string getAsString(bool InAttrGrp = false) const; 184c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling 1858c74ecfbddabe89e150abff4fdff0a27108874b9Bill Wendling /// \brief Equality and non-equality operators. 1862d5be6c313c0f9e23e56620fa8f8ae8d9b539bf0Bill Wendling bool operator==(Attribute A) const { return pImpl == A.pImpl; } 1872d5be6c313c0f9e23e56620fa8f8ae8d9b539bf0Bill Wendling bool operator!=(Attribute A) const { return pImpl != A.pImpl; } 1882d5be6c313c0f9e23e56620fa8f8ae8d9b539bf0Bill Wendling 189c08a5ef6581f2c7550e92d31f63cd65ec29c39e0Bill Wendling /// \brief Less-than operator. Useful for sorting the attributes list. 1903467e30edf63b6d8a8d446186674ba9e4b7885a9Bill Wendling bool operator<(Attribute A) const; 1913467e30edf63b6d8a8d446186674ba9e4b7885a9Bill Wendling 192bb08593980b16fbd9758da6ca4fa9c7964f2f926Bill Wendling void Profile(FoldingSetNodeID &ID) const { 193bb08593980b16fbd9758da6ca4fa9c7964f2f926Bill Wendling ID.AddPointer(pImpl); 194bb08593980b16fbd9758da6ca4fa9c7964f2f926Bill Wendling } 195827cde1c8319e51463007078a7ce3660ebc93036Duncan Sands}; 196827cde1c8319e51463007078a7ce3660ebc93036Duncan Sands 197e66f3d3ba0ea9f82f65a29c47fc37e997cbf0aceBill Wendling//===----------------------------------------------------------------------===// 19827107f6ab4627fa38bcacad6757ed6d52910f880Bill Wendling/// \class 199c3662eeaa4a1a4061fc6d5c81e3eed48c5d9da26Bill Wendling/// \brief This class holds the attributes for a function, its return value, and 200c3662eeaa4a1a4061fc6d5c81e3eed48c5d9da26Bill Wendling/// its parameters. You access the attributes for each of them via an index into 201c3662eeaa4a1a4061fc6d5c81e3eed48c5d9da26Bill Wendling/// the AttributeSet object. The function attributes are at index 202c3662eeaa4a1a4061fc6d5c81e3eed48c5d9da26Bill Wendling/// `AttributeSet::FunctionIndex', the return value is at index 203c3662eeaa4a1a4061fc6d5c81e3eed48c5d9da26Bill Wendling/// `AttributeSet::ReturnIndex', and the attributes for the parameters start at 204c3662eeaa4a1a4061fc6d5c81e3eed48c5d9da26Bill Wendling/// index `1'. 20599faa3b4ec6d03ac7808fe4ff3fbf3d04e375502Bill Wendlingclass AttributeSet { 20607aae2e7d58fe23e370e0cbb9e1a3def99434c36Bill Wendlingpublic: 20736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines enum AttrIndex : unsigned { 20807aae2e7d58fe23e370e0cbb9e1a3def99434c36Bill Wendling ReturnIndex = 0U, 20907aae2e7d58fe23e370e0cbb9e1a3def99434c36Bill Wendling FunctionIndex = ~0U 21007aae2e7d58fe23e370e0cbb9e1a3def99434c36Bill Wendling }; 21107aae2e7d58fe23e370e0cbb9e1a3def99434c36Bill Wendlingprivate: 212a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling friend class AttrBuilder; 2137d38c109aab8654e63e9071c7d948661f6b58433Bill Wendling friend class AttributeSetImpl; 21416274258d16342a2f91aaa3690b78ce74e4105f1Bill Wendling template <typename Ty> friend struct DenseMapInfo; 215a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling 21673dee180c836270644dfa7d90f9c5ba877567999Bill Wendling /// \brief The attributes that we are managing. This can be null to represent 2170976e00fd1cbf4128daeb72efd8957d00383fda9Bill Wendling /// the empty attributes list. 218ec2589863b32da169240c4fa120ef1e3798615d4Bill Wendling AttributeSetImpl *pImpl; 2190976e00fd1cbf4128daeb72efd8957d00383fda9Bill Wendling 22073dee180c836270644dfa7d90f9c5ba877567999Bill Wendling /// \brief The attributes for the specified index are returned. 2218a6a7bb6a601061031cddd77129532a3b467300bBill Wendling AttributeSetNode *getAttributes(unsigned Index) const; 2220976e00fd1cbf4128daeb72efd8957d00383fda9Bill Wendling 22387e10dfefa94f77937c37b0eb51095540d675cbcBill Wendling /// \brief Create an AttributeSet with the specified parameters in it. 22487e10dfefa94f77937c37b0eb51095540d675cbcBill Wendling static AttributeSet get(LLVMContext &C, 2256bdbf061c353295669b6bfc271b948158602d1bcBill Wendling ArrayRef<std::pair<unsigned, Attribute> > Attrs); 22687e10dfefa94f77937c37b0eb51095540d675cbcBill Wendling static AttributeSet get(LLVMContext &C, 2276bdbf061c353295669b6bfc271b948158602d1bcBill Wendling ArrayRef<std::pair<unsigned, 22887e10dfefa94f77937c37b0eb51095540d675cbcBill Wendling AttributeSetNode*> > Attrs); 22987e10dfefa94f77937c37b0eb51095540d675cbcBill Wendling 23087e10dfefa94f77937c37b0eb51095540d675cbcBill Wendling static AttributeSet getImpl(LLVMContext &C, 2316bdbf061c353295669b6bfc271b948158602d1bcBill Wendling ArrayRef<std::pair<unsigned, 23287e10dfefa94f77937c37b0eb51095540d675cbcBill Wendling AttributeSetNode*> > Attrs); 23387e10dfefa94f77937c37b0eb51095540d675cbcBill Wendling 2347d38c109aab8654e63e9071c7d948661f6b58433Bill Wendling 235ec2589863b32da169240c4fa120ef1e3798615d4Bill Wendling explicit AttributeSet(AttributeSetImpl *LI) : pImpl(LI) {} 23658d74910c6b82e622ecbb57d6644d48fec5a5c0fChris Lattnerpublic: 237dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines AttributeSet() : pImpl(nullptr) {} 238710632d07b13609444626367bebd34c0af3acb6aMikhail Glushenkov 23958d74910c6b82e622ecbb57d6644d48fec5a5c0fChris Lattner //===--------------------------------------------------------------------===// 240c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling // AttributeSet Construction and Mutation 24158d74910c6b82e622ecbb57d6644d48fec5a5c0fChris Lattner //===--------------------------------------------------------------------===// 242710632d07b13609444626367bebd34c0af3acb6aMikhail Glushenkov 24318e7211068c9d2c6204512f9c468ee179818a4b6Bill Wendling /// \brief Return an AttributeSet with the specified parameters in it. 2448e47daf2858e980210f3e1f007036b24da342c29Bill Wendling static AttributeSet get(LLVMContext &C, ArrayRef<AttributeSet> Attrs); 2458a6a7bb6a601061031cddd77129532a3b467300bBill Wendling static AttributeSet get(LLVMContext &C, unsigned Index, 24632a57958226e369f964a034da2ce7083a1a34297Bill Wendling ArrayRef<Attribute::AttrKind> Kind); 247dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines static AttributeSet get(LLVMContext &C, unsigned Index, const AttrBuilder &B); 24858d74910c6b82e622ecbb57d6644d48fec5a5c0fChris Lattner 249defaca00b8087d452df2b783250a48a32658a910Bill Wendling /// \brief Add an attribute to the attribute set at the given index. Since 250defaca00b8087d452df2b783250a48a32658a910Bill Wendling /// attribute sets are immutable, this returns a new set. 2518a6a7bb6a601061031cddd77129532a3b467300bBill Wendling AttributeSet addAttribute(LLVMContext &C, unsigned Index, 252defaca00b8087d452df2b783250a48a32658a910Bill Wendling Attribute::AttrKind Attr) const; 253710632d07b13609444626367bebd34c0af3acb6aMikhail Glushenkov 2549106f73246168fb30d26fb14085c0b3d81fcd350Reed Kotler /// \brief Add an attribute to the attribute set at the given index. Since 2559106f73246168fb30d26fb14085c0b3d81fcd350Reed Kotler /// attribute sets are immutable, this returns a new set. 2568a6a7bb6a601061031cddd77129532a3b467300bBill Wendling AttributeSet addAttribute(LLVMContext &C, unsigned Index, 2579106f73246168fb30d26fb14085c0b3d81fcd350Reed Kotler StringRef Kind) const; 2589e2ef7780b91d8e01a9ab172f80272fc94f6956bBill Wendling AttributeSet addAttribute(LLVMContext &C, unsigned Index, 2599e2ef7780b91d8e01a9ab172f80272fc94f6956bBill Wendling StringRef Kind, StringRef Value) const; 2609106f73246168fb30d26fb14085c0b3d81fcd350Reed Kotler 261e4e85f17564c28cd571dda30146c3f310521acf0Bill Wendling /// \brief Add attributes to the attribute set at the given index. Since 262e4e85f17564c28cd571dda30146c3f310521acf0Bill Wendling /// attribute sets are immutable, this returns a new set. 2638a6a7bb6a601061031cddd77129532a3b467300bBill Wendling AttributeSet addAttributes(LLVMContext &C, unsigned Index, 264e4e85f17564c28cd571dda30146c3f310521acf0Bill Wendling AttributeSet Attrs) const; 265e4e85f17564c28cd571dda30146c3f310521acf0Bill Wendling 26618e7211068c9d2c6204512f9c468ee179818a4b6Bill Wendling /// \brief Remove the specified attribute at the specified index from this 2678246df61f6de716acf1f8c64fac3c19970a2c174Bill Wendling /// attribute list. Since attribute lists are immutable, this returns the new 26818e7211068c9d2c6204512f9c468ee179818a4b6Bill Wendling /// list. 2698a6a7bb6a601061031cddd77129532a3b467300bBill Wendling AttributeSet removeAttribute(LLVMContext &C, unsigned Index, 2708246df61f6de716acf1f8c64fac3c19970a2c174Bill Wendling Attribute::AttrKind Attr) const; 2718246df61f6de716acf1f8c64fac3c19970a2c174Bill Wendling 2728246df61f6de716acf1f8c64fac3c19970a2c174Bill Wendling /// \brief Remove the specified attributes at the specified index from this 2738246df61f6de716acf1f8c64fac3c19970a2c174Bill Wendling /// attribute list. Since attribute lists are immutable, this returns the new 2748246df61f6de716acf1f8c64fac3c19970a2c174Bill Wendling /// list. 2758a6a7bb6a601061031cddd77129532a3b467300bBill Wendling AttributeSet removeAttributes(LLVMContext &C, unsigned Index, 2768246df61f6de716acf1f8c64fac3c19970a2c174Bill Wendling AttributeSet Attrs) const; 277710632d07b13609444626367bebd34c0af3acb6aMikhail Glushenkov 27858d74910c6b82e622ecbb57d6644d48fec5a5c0fChris Lattner //===--------------------------------------------------------------------===// 279c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling // AttributeSet Accessors 28058d74910c6b82e622ecbb57d6644d48fec5a5c0fChris Lattner //===--------------------------------------------------------------------===// 28118e7211068c9d2c6204512f9c468ee179818a4b6Bill Wendling 28285b3fbecdfe934ac7519a8831c4bd262cba99d12Bill Wendling /// \brief Retrieve the LLVM context. 28385b3fbecdfe934ac7519a8831c4bd262cba99d12Bill Wendling LLVMContext &getContext() const; 28485b3fbecdfe934ac7519a8831c4bd262cba99d12Bill Wendling 28518e7211068c9d2c6204512f9c468ee179818a4b6Bill Wendling /// \brief The attributes for the specified index are returned. 2868a6a7bb6a601061031cddd77129532a3b467300bBill Wendling AttributeSet getParamAttributes(unsigned Index) const; 28719c874638d9478a5d5028854817a5ee72293bb2bDevang Patel 28818e7211068c9d2c6204512f9c468ee179818a4b6Bill Wendling /// \brief The attributes for the ret value are returned. 2893fc4b96b503fa202411317684a2ba02e41e43072Bill Wendling AttributeSet getRetAttributes() const; 29019c874638d9478a5d5028854817a5ee72293bb2bDevang Patel 29118e7211068c9d2c6204512f9c468ee179818a4b6Bill Wendling /// \brief The function attributes are returned. 292c5f1bc88a2eb7ad9ff924ca90cf88494e5f947b9Bill Wendling AttributeSet getFnAttributes() const; 293710632d07b13609444626367bebd34c0af3acb6aMikhail Glushenkov 294831737d329a727f53a1fb0572f7b7a8127208881Bill Wendling /// \brief Return true if the attribute exists at the given index. 29519d815c04fde6b7b53c2b542813157edfa213842Bill Wendling bool hasAttribute(unsigned Index, Attribute::AttrKind Kind) const; 296831737d329a727f53a1fb0572f7b7a8127208881Bill Wendling 2970e9d5d059c4aa959e9ef4dff011dbd38d45a1016Bill Wendling /// \brief Return true if the attribute exists at the given index. 2980e9d5d059c4aa959e9ef4dff011dbd38d45a1016Bill Wendling bool hasAttribute(unsigned Index, StringRef Kind) const; 2990e9d5d059c4aa959e9ef4dff011dbd38d45a1016Bill Wendling 300831737d329a727f53a1fb0572f7b7a8127208881Bill Wendling /// \brief Return true if attribute exists at the given index. 30119d815c04fde6b7b53c2b542813157edfa213842Bill Wendling bool hasAttributes(unsigned Index) const; 302831737d329a727f53a1fb0572f7b7a8127208881Bill Wendling 303c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling /// \brief Return true if the specified attribute is set for at least one 304c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling /// parameter or for the return value. 305c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling bool hasAttrSomewhere(Attribute::AttrKind Attr) const; 306c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling 3070e9d5d059c4aa959e9ef4dff011dbd38d45a1016Bill Wendling /// \brief Return the attribute object that exists at the given index. 3080e9d5d059c4aa959e9ef4dff011dbd38d45a1016Bill Wendling Attribute getAttribute(unsigned Index, Attribute::AttrKind Kind) const; 3090e9d5d059c4aa959e9ef4dff011dbd38d45a1016Bill Wendling 3100e9d5d059c4aa959e9ef4dff011dbd38d45a1016Bill Wendling /// \brief Return the attribute object that exists at the given index. 3110e9d5d059c4aa959e9ef4dff011dbd38d45a1016Bill Wendling Attribute getAttribute(unsigned Index, StringRef Kind) const; 3120e9d5d059c4aa959e9ef4dff011dbd38d45a1016Bill Wendling 31349f6060f16aec4024d644a6ec4ddd3de9b3e8821Bill Wendling /// \brief Return the alignment for the specified function parameter. 3148a6a7bb6a601061031cddd77129532a3b467300bBill Wendling unsigned getParamAlignment(unsigned Index) const; 3158e47daf2858e980210f3e1f007036b24da342c29Bill Wendling 316831737d329a727f53a1fb0572f7b7a8127208881Bill Wendling /// \brief Get the stack alignment. 31719d815c04fde6b7b53c2b542813157edfa213842Bill Wendling unsigned getStackAlignment(unsigned Index) const; 318831737d329a727f53a1fb0572f7b7a8127208881Bill Wendling 319831737d329a727f53a1fb0572f7b7a8127208881Bill Wendling /// \brief Return the attributes at the index as a string. 320aae0298921d946a64385052ce6e678d36f936fb3Rafael Espindola std::string getAsString(unsigned Index, bool InAttrGrp = false) const; 321831737d329a727f53a1fb0572f7b7a8127208881Bill Wendling 32216c4b3cf2943ae2327752cf3de39769d14cfceceBill Wendling typedef ArrayRef<Attribute>::iterator iterator; 32316c4b3cf2943ae2327752cf3de39769d14cfceceBill Wendling 3248a6a7bb6a601061031cddd77129532a3b467300bBill Wendling iterator begin(unsigned Slot) const; 3258a6a7bb6a601061031cddd77129532a3b467300bBill Wendling iterator end(unsigned Slot) const; 32616c4b3cf2943ae2327752cf3de39769d14cfceceBill Wendling 327041221c0972ff575b07f76808c504833d629ae1fChris Lattner /// operator==/!= - Provide equality predicates. 32818e7211068c9d2c6204512f9c468ee179818a4b6Bill Wendling bool operator==(const AttributeSet &RHS) const { 329ec2589863b32da169240c4fa120ef1e3798615d4Bill Wendling return pImpl == RHS.pImpl; 33018e7211068c9d2c6204512f9c468ee179818a4b6Bill Wendling } 33118e7211068c9d2c6204512f9c468ee179818a4b6Bill Wendling bool operator!=(const AttributeSet &RHS) const { 332ec2589863b32da169240c4fa120ef1e3798615d4Bill Wendling return pImpl != RHS.pImpl; 33318e7211068c9d2c6204512f9c468ee179818a4b6Bill Wendling } 334710632d07b13609444626367bebd34c0af3acb6aMikhail Glushenkov 33558d74910c6b82e622ecbb57d6644d48fec5a5c0fChris Lattner //===--------------------------------------------------------------------===// 336c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling // AttributeSet Introspection 33758d74910c6b82e622ecbb57d6644d48fec5a5c0fChris Lattner //===--------------------------------------------------------------------===// 338710632d07b13609444626367bebd34c0af3acb6aMikhail Glushenkov 339c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling // FIXME: Remove this. 340c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling uint64_t Raw(unsigned Index) const; 341c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling 34218e7211068c9d2c6204512f9c468ee179818a4b6Bill Wendling /// \brief Return a raw pointer that uniquely identifies this attribute list. 34358d74910c6b82e622ecbb57d6644d48fec5a5c0fChris Lattner void *getRawPointer() const { 344ec2589863b32da169240c4fa120ef1e3798615d4Bill Wendling return pImpl; 34558d74910c6b82e622ecbb57d6644d48fec5a5c0fChris Lattner } 346710632d07b13609444626367bebd34c0af3acb6aMikhail Glushenkov 34718e7211068c9d2c6204512f9c468ee179818a4b6Bill Wendling /// \brief Return true if there are no attributes. 34858d74910c6b82e622ecbb57d6644d48fec5a5c0fChris Lattner bool isEmpty() const { 349aa57893e84ba7a35948fcaa99812ba88e58f4797Bill Wendling return getNumSlots() == 0; 35058d74910c6b82e622ecbb57d6644d48fec5a5c0fChris Lattner } 351710632d07b13609444626367bebd34c0af3acb6aMikhail Glushenkov 35218e7211068c9d2c6204512f9c468ee179818a4b6Bill Wendling /// \brief Return the number of slots used in this attribute list. This is 35318e7211068c9d2c6204512f9c468ee179818a4b6Bill Wendling /// the number of arguments that have an attribute set on them (including the 35418e7211068c9d2c6204512f9c468ee179818a4b6Bill Wendling /// function itself). 35558d74910c6b82e622ecbb57d6644d48fec5a5c0fChris Lattner unsigned getNumSlots() const; 356710632d07b13609444626367bebd34c0af3acb6aMikhail Glushenkov 357e1f95db4803a48a30fc2a1d5868281a87a36fb85Bill Wendling /// \brief Return the index for the given slot. 35876f103e02164d27b41bd92a9767c7012482ba31aRafael Espindola unsigned getSlotIndex(unsigned Slot) const; 359e1f95db4803a48a30fc2a1d5868281a87a36fb85Bill Wendling 3608e47daf2858e980210f3e1f007036b24da342c29Bill Wendling /// \brief Return the attributes at the given slot. 3618e47daf2858e980210f3e1f007036b24da342c29Bill Wendling AttributeSet getSlotAttributes(unsigned Slot) const; 3628e47daf2858e980210f3e1f007036b24da342c29Bill Wendling 363f3d1500ab2c7364d3d0fb73a7e1b8c6339ab48b1Bill Wendling void dump() const; 36458d74910c6b82e622ecbb57d6644d48fec5a5c0fChris Lattner}; 3654f859aa532dbf061736f9c23e0d0882b5cdfe566Reid Spencer 366a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling//===----------------------------------------------------------------------===// 367a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling/// \class 36816274258d16342a2f91aaa3690b78ce74e4105f1Bill Wendling/// \brief Provide DenseMapInfo for AttributeSet. 36916274258d16342a2f91aaa3690b78ce74e4105f1Bill Wendlingtemplate<> struct DenseMapInfo<AttributeSet> { 37016274258d16342a2f91aaa3690b78ce74e4105f1Bill Wendling static inline AttributeSet getEmptyKey() { 37116274258d16342a2f91aaa3690b78ce74e4105f1Bill Wendling uintptr_t Val = static_cast<uintptr_t>(-1); 37216274258d16342a2f91aaa3690b78ce74e4105f1Bill Wendling Val <<= PointerLikeTypeTraits<void*>::NumLowBitsAvailable; 37316274258d16342a2f91aaa3690b78ce74e4105f1Bill Wendling return AttributeSet(reinterpret_cast<AttributeSetImpl*>(Val)); 374c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling } 37516274258d16342a2f91aaa3690b78ce74e4105f1Bill Wendling static inline AttributeSet getTombstoneKey() { 37616274258d16342a2f91aaa3690b78ce74e4105f1Bill Wendling uintptr_t Val = static_cast<uintptr_t>(-2); 37716274258d16342a2f91aaa3690b78ce74e4105f1Bill Wendling Val <<= PointerLikeTypeTraits<void*>::NumLowBitsAvailable; 37816274258d16342a2f91aaa3690b78ce74e4105f1Bill Wendling return AttributeSet(reinterpret_cast<AttributeSetImpl*>(Val)); 379c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling } 38016274258d16342a2f91aaa3690b78ce74e4105f1Bill Wendling static unsigned getHashValue(AttributeSet AS) { 38116274258d16342a2f91aaa3690b78ce74e4105f1Bill Wendling return (unsigned((uintptr_t)AS.pImpl) >> 4) ^ 38216274258d16342a2f91aaa3690b78ce74e4105f1Bill Wendling (unsigned((uintptr_t)AS.pImpl) >> 9); 383c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling } 38416274258d16342a2f91aaa3690b78ce74e4105f1Bill Wendling static bool isEqual(AttributeSet LHS, AttributeSet RHS) { return LHS == RHS; } 385c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling}; 386c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling 387c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling//===----------------------------------------------------------------------===// 388c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling/// \class 389a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling/// \brief This class is used in conjunction with the Attribute::get method to 390a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling/// create an Attribute object. The object itself is uniquified. The Builder's 391a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling/// value, however, is not. So this can be used as a quick way to test for 392a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling/// equality, presence of attributes, etc. 393a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendlingclass AttrBuilder { 3943f213e7b3a6829a154d4e8ceb7d8689b389bd5dcBenjamin Kramer std::bitset<Attribute::EndAttrKinds> Attrs; 395ea59f896a672c2e1ef9f02277bce60257aa60989Bill Wendling std::map<std::string, std::string> TargetDepAttrs; 396a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling uint64_t Alignment; 397a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling uint64_t StackAlignment; 398a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendlingpublic: 399c835b8c30127d15599de2d614434d39a6cc3ae17Benjamin Kramer AttrBuilder() : Attrs(0), Alignment(0), StackAlignment(0) {} 400c835b8c30127d15599de2d614434d39a6cc3ae17Benjamin Kramer explicit AttrBuilder(uint64_t Val) 401c835b8c30127d15599de2d614434d39a6cc3ae17Benjamin Kramer : Attrs(0), Alignment(0), StackAlignment(0) { 402f9271ea159b97e2febedcf095c3c4122cb24d077Bill Wendling addRawValue(Val); 403a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling } 404c835b8c30127d15599de2d614434d39a6cc3ae17Benjamin Kramer AttrBuilder(const Attribute &A) : Attrs(0), Alignment(0), StackAlignment(0) { 40539da078977ae98b6bf1c3c76a472ed24f5f2a2d2Bill Wendling addAttribute(A); 406a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling } 407a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling AttrBuilder(AttributeSet AS, unsigned Idx); 408a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling 409a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling void clear(); 410a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling 411a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling /// \brief Add an attribute to the builder. 412a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling AttrBuilder &addAttribute(Attribute::AttrKind Val); 413a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling 41439da078977ae98b6bf1c3c76a472ed24f5f2a2d2Bill Wendling /// \brief Add the Attribute object to the builder. 41539da078977ae98b6bf1c3c76a472ed24f5f2a2d2Bill Wendling AttrBuilder &addAttribute(Attribute A); 41639da078977ae98b6bf1c3c76a472ed24f5f2a2d2Bill Wendling 417ea59f896a672c2e1ef9f02277bce60257aa60989Bill Wendling /// \brief Add the target-dependent attribute to the builder. 418ad19d9c4228718b0ac167d0dfa013d14c3c9f135Bill Wendling AttrBuilder &addAttribute(StringRef A, StringRef V = StringRef()); 419ea59f896a672c2e1ef9f02277bce60257aa60989Bill Wendling 420a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling /// \brief Remove an attribute from the builder. 421a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling AttrBuilder &removeAttribute(Attribute::AttrKind Val); 422a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling 42349f6060f16aec4024d644a6ec4ddd3de9b3e8821Bill Wendling /// \brief Remove the attributes from the builder. 424e74365462a39529ae48ef4d34ec76b4543b8ea29Bill Wendling AttrBuilder &removeAttributes(AttributeSet A, uint64_t Index); 425a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling 426ea59f896a672c2e1ef9f02277bce60257aa60989Bill Wendling /// \brief Remove the target-dependent attribute to the builder. 427ea59f896a672c2e1ef9f02277bce60257aa60989Bill Wendling AttrBuilder &removeAttribute(StringRef A); 428ea59f896a672c2e1ef9f02277bce60257aa60989Bill Wendling 42985df6b43403d3ebf5d80023a85699c6fb254941aBill Wendling /// \brief Add the attributes from the builder. 43085df6b43403d3ebf5d80023a85699c6fb254941aBill Wendling AttrBuilder &merge(const AttrBuilder &B); 43185df6b43403d3ebf5d80023a85699c6fb254941aBill Wendling 432a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling /// \brief Return true if the builder has the specified attribute. 433c835b8c30127d15599de2d614434d39a6cc3ae17Benjamin Kramer bool contains(Attribute::AttrKind A) const { 4343f213e7b3a6829a154d4e8ceb7d8689b389bd5dcBenjamin Kramer assert((unsigned)A < Attribute::EndAttrKinds && "Attribute out of range!"); 4353f213e7b3a6829a154d4e8ceb7d8689b389bd5dcBenjamin Kramer return Attrs[A]; 436c835b8c30127d15599de2d614434d39a6cc3ae17Benjamin Kramer } 437a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling 438c342d9d345acdbd95577c7c6e9ce7d3a1bdb57bfBill Wendling /// \brief Return true if the builder has the specified target-dependent 439c342d9d345acdbd95577c7c6e9ce7d3a1bdb57bfBill Wendling /// attribute. 440c342d9d345acdbd95577c7c6e9ce7d3a1bdb57bfBill Wendling bool contains(StringRef A) const; 441c342d9d345acdbd95577c7c6e9ce7d3a1bdb57bfBill Wendling 442a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling /// \brief Return true if the builder has IR-level attributes. 443a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling bool hasAttributes() const; 444a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling 445a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling /// \brief Return true if the builder has any attribute that's in the 446a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling /// specified attribute. 447e74365462a39529ae48ef4d34ec76b4543b8ea29Bill Wendling bool hasAttributes(AttributeSet A, uint64_t Index) const; 448a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling 449a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling /// \brief Return true if the builder has an alignment attribute. 450a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling bool hasAlignmentAttr() const; 451a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling 452a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling /// \brief Retrieve the alignment attribute, if it exists. 453a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling uint64_t getAlignment() const { return Alignment; } 454a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling 455a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling /// \brief Retrieve the stack alignment attribute, if it exists. 456a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling uint64_t getStackAlignment() const { return StackAlignment; } 457a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling 458a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling /// \brief This turns an int alignment (which must be a power of 2) into the 459a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling /// form used internally in Attribute. 460a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling AttrBuilder &addAlignmentAttr(unsigned Align); 461a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling 462a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling /// \brief This turns an int stack alignment (which must be a power of 2) into 463a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling /// the form used internally in Attribute. 464a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling AttrBuilder &addStackAlignmentAttr(unsigned Align); 465a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling 466c835b8c30127d15599de2d614434d39a6cc3ae17Benjamin Kramer /// \brief Return true if the builder contains no target-independent 467c835b8c30127d15599de2d614434d39a6cc3ae17Benjamin Kramer /// attributes. 4683f213e7b3a6829a154d4e8ceb7d8689b389bd5dcBenjamin Kramer bool empty() const { return Attrs.none(); } 46987de71cb9f12d874e88d4f314ab245985c1b36bcBill Wendling 47064754f499058b5dc748ea6d06a084af0ed539ec4Bill Wendling // Iterators for target-dependent attributes. 47164754f499058b5dc748ea6d06a084af0ed539ec4Bill Wendling typedef std::pair<std::string, std::string> td_type; 47264754f499058b5dc748ea6d06a084af0ed539ec4Bill Wendling typedef std::map<std::string, std::string>::iterator td_iterator; 47364754f499058b5dc748ea6d06a084af0ed539ec4Bill Wendling typedef std::map<std::string, std::string>::const_iterator td_const_iterator; 474dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines typedef llvm::iterator_range<td_iterator> td_range; 475dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines typedef llvm::iterator_range<td_const_iterator> td_const_range; 47664754f499058b5dc748ea6d06a084af0ed539ec4Bill Wendling 47764754f499058b5dc748ea6d06a084af0ed539ec4Bill Wendling td_iterator td_begin() { return TargetDepAttrs.begin(); } 47864754f499058b5dc748ea6d06a084af0ed539ec4Bill Wendling td_iterator td_end() { return TargetDepAttrs.end(); } 47964754f499058b5dc748ea6d06a084af0ed539ec4Bill Wendling 48064754f499058b5dc748ea6d06a084af0ed539ec4Bill Wendling td_const_iterator td_begin() const { return TargetDepAttrs.begin(); } 48164754f499058b5dc748ea6d06a084af0ed539ec4Bill Wendling td_const_iterator td_end() const { return TargetDepAttrs.end(); } 48264754f499058b5dc748ea6d06a084af0ed539ec4Bill Wendling 483dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines td_range td_attrs() { return td_range(td_begin(), td_end()); } 484dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines td_const_range td_attrs() const { 485dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines return td_const_range(td_begin(), td_end()); 486dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines } 487dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines 48887de71cb9f12d874e88d4f314ab245985c1b36bcBill Wendling bool td_empty() const { return TargetDepAttrs.empty(); } 48987de71cb9f12d874e88d4f314ab245985c1b36bcBill Wendling 490a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling bool operator==(const AttrBuilder &B); 491a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling bool operator!=(const AttrBuilder &B) { 492a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling return !(*this == B); 493a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling } 494c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling 495f9271ea159b97e2febedcf095c3c4122cb24d077Bill Wendling // FIXME: Remove this in 4.0. 496c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling 497c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling /// \brief Add the raw value to the internal representation. 498c22f4aa886443507f8406d30d118fdeeac6a8c6cBill Wendling AttrBuilder &addRawValue(uint64_t Val); 499a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling}; 500a90a99a82b9c5c39fc6dbee9c266dcd7b107fe2fBill Wendling 5018e47daf2858e980210f3e1f007036b24da342c29Bill Wendlingnamespace AttributeFuncs { 5028e47daf2858e980210f3e1f007036b24da342c29Bill Wendling 5038e47daf2858e980210f3e1f007036b24da342c29Bill Wendling/// \brief Which attributes cannot be applied to a type. 504e74365462a39529ae48ef4d34ec76b4543b8ea29Bill WendlingAttributeSet typeIncompatible(Type *Ty, uint64_t Index); 5058e47daf2858e980210f3e1f007036b24da342c29Bill Wendling 5068e47daf2858e980210f3e1f007036b24da342c29Bill Wendling} // end AttributeFuncs namespace 5078e47daf2858e980210f3e1f007036b24da342c29Bill Wendling 50827107f6ab4627fa38bcacad6757ed6d52910f880Bill Wendling} // end llvm namespace 5096091ebd172a16a10f1ea66061a5fa7cbf5139e56Reid Spencer 5106091ebd172a16a10f1ea66061a5fa7cbf5139e56Reid Spencer#endif 511