2008-09-25 21:00:45 +00:00
|
|
|
//===-- llvm/Attributes.h - Container for Attributes ---*---------- C++ -*-===//
|
2007-04-08 14:46:50 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 19:59:42 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-04-08 14:46:50 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2008-09-25 21:00:45 +00:00
|
|
|
// This file contains the simple types necessary to represent the
|
2008-02-22 22:17:59 +00:00
|
|
|
// attributes associated with functions and their calls.
|
2007-04-08 14:46:50 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-09-25 21:00:45 +00:00
|
|
|
#ifndef LLVM_ATTRIBUTES_H
|
|
|
|
#define LLVM_ATTRIBUTES_H
|
2007-04-08 14:46:50 +00:00
|
|
|
|
2008-12-19 06:39:12 +00:00
|
|
|
#include "llvm/Support/MathExtras.h"
|
2008-09-27 00:08:24 +00:00
|
|
|
#include <cassert>
|
2008-03-12 17:45:29 +00:00
|
|
|
#include <string>
|
2007-04-08 14:46:50 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
2008-01-06 18:27:01 +00:00
|
|
|
class Type;
|
|
|
|
|
2008-09-25 21:00:45 +00:00
|
|
|
/// Attributes - A bitset of attributes.
|
2008-09-23 23:03:40 +00:00
|
|
|
typedef unsigned Attributes;
|
2008-12-19 06:39:12 +00:00
|
|
|
|
2008-09-25 21:00:45 +00:00
|
|
|
namespace Attribute {
|
2007-04-11 02:44:20 +00:00
|
|
|
|
2007-04-22 17:28:03 +00:00
|
|
|
/// Function parameters and results can have attributes to indicate how they
|
|
|
|
/// should be treated by optimizations and code generation. This enumeration
|
2008-09-25 21:00:45 +00:00
|
|
|
/// lists the attributes that can be associated with parameters, function
|
|
|
|
/// results or the function itself.
|
|
|
|
/// @brief Function attributes.
|
2008-02-19 21:38:47 +00:00
|
|
|
|
|
|
|
const Attributes None = 0; ///< No attributes have been set
|
|
|
|
const Attributes ZExt = 1<<0; ///< Zero extended before/after call
|
|
|
|
const Attributes SExt = 1<<1; ///< Sign extended before/after call
|
|
|
|
const Attributes NoReturn = 1<<2; ///< Mark the function as not returning
|
|
|
|
const Attributes InReg = 1<<3; ///< Force argument to be passed in register
|
|
|
|
const Attributes StructRet = 1<<4; ///< Hidden pointer to structure to return
|
|
|
|
const Attributes NoUnwind = 1<<5; ///< Function doesn't unwind stack
|
|
|
|
const Attributes NoAlias = 1<<6; ///< Considered to not alias after call
|
|
|
|
const Attributes ByVal = 1<<7; ///< Pass structure by value
|
|
|
|
const Attributes Nest = 1<<8; ///< Nested function static chain
|
|
|
|
const Attributes ReadNone = 1<<9; ///< Function does not access memory
|
|
|
|
const Attributes ReadOnly = 1<<10; ///< Function only reads from memory
|
2008-12-19 06:39:12 +00:00
|
|
|
const Attributes NoInline = 1<<11; ///< inline=never
|
|
|
|
const Attributes AlwaysInline = 1<<12; ///< inline=always
|
|
|
|
const Attributes OptimizeForSize = 1<<13; ///< opt_size
|
|
|
|
const Attributes StackProtect = 1<<14; ///< Stack protection.
|
|
|
|
const Attributes StackProtectReq = 1<<15; ///< Stack protection required.
|
|
|
|
const Attributes Alignment = 31<<16; ///< Alignment of parameter (5 bits)
|
|
|
|
// stored as log2 of alignment with +1 bias
|
|
|
|
// 0 means unaligned different from align 1
|
|
|
|
const Attributes NoCapture = 1<<21; ///< Function creates no aliases of pointer
|
2009-06-04 22:05:33 +00:00
|
|
|
const Attributes NoRedZone = 1<<22; /// disable redzone
|
2009-06-05 21:57:13 +00:00
|
|
|
const Attributes NoImplicitFloat = 1<<23; /// disable implicit floating point
|
|
|
|
/// instructions.
|
2009-08-26 01:08:21 +00:00
|
|
|
const Attributes Naked = 1<<24; ///< Naked function
|
|
|
|
const Attributes InlineHint = 1<<25; ///< source said inlining was desirable
|
2008-12-19 06:39:12 +00:00
|
|
|
|
2007-11-25 14:10:56 +00:00
|
|
|
/// @brief Attributes that only apply to function parameters.
|
2008-12-19 06:39:12 +00:00
|
|
|
const Attributes ParameterOnly = ByVal | Nest | StructRet | NoCapture;
|
2007-11-25 14:10:56 +00:00
|
|
|
|
2009-06-11 08:11:03 +00:00
|
|
|
/// @brief Attributes that may be applied to the function itself. These cannot
|
|
|
|
/// be used on return values or function parameters.
|
2008-10-03 21:11:02 +00:00
|
|
|
const Attributes FunctionOnly = NoReturn | NoUnwind | ReadNone | ReadOnly |
|
2009-06-04 22:05:33 +00:00
|
|
|
NoInline | AlwaysInline | OptimizeForSize | StackProtect | StackProtectReq |
|
2009-08-26 01:08:21 +00:00
|
|
|
NoRedZone | NoImplicitFloat | Naked | InlineHint;
|
2007-11-25 14:10:56 +00:00
|
|
|
|
2008-01-12 16:42:01 +00:00
|
|
|
/// @brief Parameter attributes that do not apply to vararg call arguments.
|
2008-02-19 21:38:47 +00:00
|
|
|
const Attributes VarArgsIncompatible = StructRet;
|
2008-01-11 22:36:48 +00:00
|
|
|
|
2007-11-25 14:10:56 +00:00
|
|
|
/// @brief Attributes that are mutually incompatible.
|
2008-10-01 23:41:25 +00:00
|
|
|
const Attributes MutuallyIncompatible[4] = {
|
2008-12-19 06:39:12 +00:00
|
|
|
ByVal | InReg | Nest | StructRet,
|
2007-11-25 14:10:56 +00:00
|
|
|
ZExt | SExt,
|
2008-10-01 23:41:25 +00:00
|
|
|
ReadNone | ReadOnly,
|
|
|
|
NoInline | AlwaysInline
|
2007-11-25 14:10:56 +00:00
|
|
|
};
|
|
|
|
|
2008-01-07 17:16:06 +00:00
|
|
|
/// @brief Which attributes cannot be applied to a type.
|
2008-03-12 17:45:29 +00:00
|
|
|
Attributes typeIncompatible(const Type *Ty);
|
2008-01-06 18:27:01 +00:00
|
|
|
|
2008-02-22 17:49:45 +00:00
|
|
|
/// This turns an int alignment (a power of 2, normally) into the
|
2008-09-23 23:03:40 +00:00
|
|
|
/// form used internally in Attributes.
|
|
|
|
inline Attributes constructAlignmentFromInt(unsigned i) {
|
2008-12-19 06:39:12 +00:00
|
|
|
// Default alignment, allow the target to define how to align it.
|
|
|
|
if (i == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
assert(isPowerOf2_32(i) && "Alignment must be a power of two.");
|
|
|
|
assert(i <= 0x40000000 && "Alignment too large.");
|
|
|
|
return (Log2_32(i)+1) << 16;
|
2008-02-22 17:49:45 +00:00
|
|
|
}
|
|
|
|
|
2008-12-31 08:41:38 +00:00
|
|
|
/// This returns the alignment field of an attribute as a byte alignment value.
|
|
|
|
inline unsigned getAlignmentFromAttrs(Attributes A) {
|
|
|
|
Attributes Align = A & Attribute::Alignment;
|
|
|
|
if (Align == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1U << ((Align >> 16) - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-23 23:03:40 +00:00
|
|
|
/// The set of Attributes set in Attributes is converted to a
|
2008-03-12 17:45:29 +00:00
|
|
|
/// string of equivalent mnemonics. This is, presumably, for writing out
|
|
|
|
/// the mnemonics for the assembly writer.
|
2008-09-25 21:00:45 +00:00
|
|
|
/// @brief Convert attribute bits to text
|
2008-09-23 23:03:40 +00:00
|
|
|
std::string getAsString(Attributes Attrs);
|
2008-09-25 21:00:45 +00:00
|
|
|
} // end namespace Attribute
|
|
|
|
|
|
|
|
/// This is just a pair of values to associate a set of attributes
|
|
|
|
/// with an index.
|
|
|
|
struct AttributeWithIndex {
|
2008-09-23 23:03:40 +00:00
|
|
|
Attributes Attrs; ///< The attributes that are set, or'd together.
|
2008-03-12 17:45:29 +00:00
|
|
|
unsigned Index; ///< Index of the parameter for which the attributes apply.
|
2008-09-25 21:00:45 +00:00
|
|
|
///< Index 0 is used for return value attributes.
|
|
|
|
///< Index ~0U is used for function attributes.
|
2007-06-18 21:50:49 +00:00
|
|
|
|
2008-09-25 21:00:45 +00:00
|
|
|
static AttributeWithIndex get(unsigned Idx, Attributes Attrs) {
|
|
|
|
AttributeWithIndex P;
|
2008-03-12 17:45:29 +00:00
|
|
|
P.Index = Idx;
|
|
|
|
P.Attrs = Attrs;
|
2007-06-18 21:50:49 +00:00
|
|
|
return P;
|
|
|
|
}
|
2007-04-22 05:46:44 +00:00
|
|
|
};
|
2008-03-12 17:45:29 +00:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
2008-09-25 21:00:45 +00:00
|
|
|
// AttrListPtr Smart Pointer
|
2008-03-12 17:45:29 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-09-24 00:29:49 +00:00
|
|
|
class AttributeListImpl;
|
2008-03-12 17:45:29 +00:00
|
|
|
|
2008-09-25 21:00:45 +00:00
|
|
|
/// AttrListPtr - This class manages the ref count for the opaque
|
2008-09-24 00:29:49 +00:00
|
|
|
/// AttributeListImpl object and provides accessors for it.
|
2008-09-25 21:00:45 +00:00
|
|
|
class AttrListPtr {
|
|
|
|
/// AttrList - The attributes that we are managing. This can be null
|
|
|
|
/// to represent the empty attributes list.
|
|
|
|
AttributeListImpl *AttrList;
|
2008-03-12 17:45:29 +00:00
|
|
|
public:
|
2008-09-25 21:00:45 +00:00
|
|
|
AttrListPtr() : AttrList(0) {}
|
|
|
|
AttrListPtr(const AttrListPtr &P);
|
|
|
|
const AttrListPtr &operator=(const AttrListPtr &RHS);
|
|
|
|
~AttrListPtr();
|
2008-03-12 17:45:29 +00:00
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
2008-09-25 21:00:45 +00:00
|
|
|
// Attribute List Construction and Mutation
|
2008-03-12 17:45:29 +00:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
|
2008-09-25 21:00:45 +00:00
|
|
|
/// get - Return a Attributes list with the specified parameter in it.
|
|
|
|
static AttrListPtr get(const AttributeWithIndex *Attr, unsigned NumAttrs);
|
2008-03-12 17:45:29 +00:00
|
|
|
|
2008-09-25 21:00:45 +00:00
|
|
|
/// get - Return a Attribute list with the parameters specified by the
|
2008-03-13 04:33:03 +00:00
|
|
|
/// consecutive random access iterator range.
|
2008-03-12 17:45:29 +00:00
|
|
|
template <typename Iter>
|
2008-09-25 21:00:45 +00:00
|
|
|
static AttrListPtr get(const Iter &I, const Iter &E) {
|
|
|
|
if (I == E) return AttrListPtr(); // Empty list.
|
2008-05-05 18:30:58 +00:00
|
|
|
return get(&*I, static_cast<unsigned>(E-I));
|
2008-03-12 17:45:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// addAttr - Add the specified attribute at the specified index to this
|
2008-09-25 21:00:45 +00:00
|
|
|
/// attribute list. Since attribute lists are immutable, this
|
2008-03-12 17:45:29 +00:00
|
|
|
/// returns the new list.
|
2008-09-25 21:00:45 +00:00
|
|
|
AttrListPtr addAttr(unsigned Idx, Attributes Attrs) const;
|
2008-03-12 17:45:29 +00:00
|
|
|
|
|
|
|
/// removeAttr - Remove the specified attribute at the specified index from
|
2008-09-25 21:00:45 +00:00
|
|
|
/// this attribute list. Since attribute lists are immutable, this
|
2008-03-12 17:45:29 +00:00
|
|
|
/// returns the new list.
|
2008-09-25 21:00:45 +00:00
|
|
|
AttrListPtr removeAttr(unsigned Idx, Attributes Attrs) const;
|
2008-03-12 17:45:29 +00:00
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
2008-09-25 21:00:45 +00:00
|
|
|
// Attribute List Accessors
|
2008-03-12 17:45:29 +00:00
|
|
|
//===--------------------------------------------------------------------===//
|
2008-09-26 22:53:05 +00:00
|
|
|
/// getParamAttributes - The attributes for the specified index are
|
|
|
|
/// returned.
|
|
|
|
Attributes getParamAttributes(unsigned Idx) const {
|
|
|
|
assert (Idx && Idx != ~0U && "Invalid parameter index!");
|
|
|
|
return getAttributes(Idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getRetAttributes - The attributes for the ret value are
|
|
|
|
/// returned.
|
|
|
|
Attributes getRetAttributes() const {
|
|
|
|
return getAttributes(0);
|
|
|
|
}
|
|
|
|
|
2008-10-15 22:55:03 +00:00
|
|
|
/// getFnAttributes - The function attributes are returned.
|
2008-09-26 22:53:05 +00:00
|
|
|
Attributes getFnAttributes() const {
|
2009-06-11 08:11:03 +00:00
|
|
|
return getAttributes(~0U);
|
2008-09-26 22:53:05 +00:00
|
|
|
}
|
2008-03-12 17:45:29 +00:00
|
|
|
|
|
|
|
/// paramHasAttr - Return true if the specified parameter index has the
|
|
|
|
/// specified attribute set.
|
2008-09-23 23:03:40 +00:00
|
|
|
bool paramHasAttr(unsigned Idx, Attributes Attr) const {
|
2008-09-25 21:00:45 +00:00
|
|
|
return getAttributes(Idx) & Attr;
|
2008-03-12 17:45:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// getParamAlignment - Return the alignment for the specified function
|
|
|
|
/// parameter.
|
|
|
|
unsigned getParamAlignment(unsigned Idx) const {
|
2008-12-31 08:41:38 +00:00
|
|
|
return Attribute::getAlignmentFromAttrs(getAttributes(Idx));
|
2008-03-12 17:45:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// hasAttrSomewhere - Return true if the specified attribute is set for at
|
|
|
|
/// least one parameter or for the return value.
|
2008-09-23 23:03:40 +00:00
|
|
|
bool hasAttrSomewhere(Attributes Attr) const;
|
2008-03-12 17:45:29 +00:00
|
|
|
|
2008-03-13 04:33:03 +00:00
|
|
|
/// operator==/!= - Provide equality predicates.
|
2008-09-25 21:00:45 +00:00
|
|
|
bool operator==(const AttrListPtr &RHS) const { return AttrList == RHS.AttrList; }
|
|
|
|
bool operator!=(const AttrListPtr &RHS) const { return AttrList != RHS.AttrList; }
|
2008-03-12 17:45:29 +00:00
|
|
|
|
|
|
|
void dump() const;
|
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
2008-09-25 21:00:45 +00:00
|
|
|
// Attribute List Introspection
|
2008-03-12 17:45:29 +00:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// getRawPointer - Return a raw pointer that uniquely identifies this
|
2008-09-25 21:00:45 +00:00
|
|
|
/// attribute list.
|
2008-03-12 17:45:29 +00:00
|
|
|
void *getRawPointer() const {
|
2008-09-25 21:00:45 +00:00
|
|
|
return AttrList;
|
2008-03-12 17:45:29 +00:00
|
|
|
}
|
|
|
|
|
2008-09-25 21:00:45 +00:00
|
|
|
// Attributes are stored as a dense set of slots, where there is one
|
2008-03-12 17:45:29 +00:00
|
|
|
// slot for each argument that has an attribute. This allows walking over the
|
|
|
|
// dense set instead of walking the sparse list of attributes.
|
|
|
|
|
2008-09-25 21:00:45 +00:00
|
|
|
/// isEmpty - Return true if there are no attributes.
|
2008-03-12 17:45:29 +00:00
|
|
|
///
|
|
|
|
bool isEmpty() const {
|
2008-09-25 21:00:45 +00:00
|
|
|
return AttrList == 0;
|
2008-03-12 17:45:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// getNumSlots - Return the number of slots used in this attribute list.
|
|
|
|
/// This is the number of arguments that have an attribute set on them
|
|
|
|
/// (including the function itself).
|
|
|
|
unsigned getNumSlots() const;
|
|
|
|
|
2008-09-25 21:00:45 +00:00
|
|
|
/// getSlot - Return the AttributeWithIndex at the specified slot. This
|
|
|
|
/// holds a index number plus a set of attributes.
|
|
|
|
const AttributeWithIndex &getSlot(unsigned Slot) const;
|
2008-03-12 17:45:29 +00:00
|
|
|
|
|
|
|
private:
|
2008-09-25 21:00:45 +00:00
|
|
|
explicit AttrListPtr(AttributeListImpl *L);
|
2008-09-26 22:53:05 +00:00
|
|
|
|
|
|
|
/// getAttributes - The attributes for the specified index are
|
|
|
|
/// returned. Attributes for the result are denoted with Idx = 0.
|
|
|
|
Attributes getAttributes(unsigned Idx) const;
|
|
|
|
|
2008-03-12 17:45:29 +00:00
|
|
|
};
|
2007-04-22 05:46:44 +00:00
|
|
|
|
2007-04-08 14:46:50 +00:00
|
|
|
} // End llvm namespace
|
|
|
|
|
|
|
|
#endif
|