2008-09-25 23:00:45 +02:00
|
|
|
//===-- llvm/Attributes.h - Container for Attributes ---*---------- C++ -*-===//
|
2007-04-08 16:46:50 +02:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:59:42 +01:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-04-08 16:46:50 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2008-09-25 23:00:45 +02:00
|
|
|
// This file contains the simple types necessary to represent the
|
2008-02-22 23:17:59 +01:00
|
|
|
// attributes associated with functions and their calls.
|
2007-04-08 16:46:50 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-09-25 23:00:45 +02:00
|
|
|
#ifndef LLVM_ATTRIBUTES_H
|
|
|
|
#define LLVM_ATTRIBUTES_H
|
2007-04-08 16:46:50 +02:00
|
|
|
|
2008-12-19 07:39:12 +01:00
|
|
|
#include "llvm/Support/MathExtras.h"
|
2008-09-27 02:08:24 +02:00
|
|
|
#include <cassert>
|
2008-03-12 18:45:29 +01:00
|
|
|
#include <string>
|
2007-04-08 16:46:50 +02:00
|
|
|
|
|
|
|
namespace llvm {
|
2008-01-06 19:27:01 +01:00
|
|
|
class Type;
|
|
|
|
|
2008-09-25 23:00:45 +02:00
|
|
|
/// Attributes - A bitset of attributes.
|
2008-09-24 01:03:40 +02:00
|
|
|
typedef unsigned Attributes;
|
2008-12-19 07:39:12 +01:00
|
|
|
|
2008-09-25 23:00:45 +02:00
|
|
|
namespace Attribute {
|
2007-04-11 04:44:20 +02:00
|
|
|
|
2007-04-22 19:28:03 +02: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 23:00:45 +02:00
|
|
|
/// lists the attributes that can be associated with parameters, function
|
|
|
|
/// results or the function itself.
|
|
|
|
/// @brief Function attributes.
|
2008-02-19 22:38:47 +01: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 07:39:12 +01: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-05 00:05:33 +02:00
|
|
|
const Attributes NoRedZone = 1<<22; /// disable redzone
|
2009-06-05 23:57:13 +02:00
|
|
|
const Attributes NoImplicitFloat = 1<<23; /// disable implicit floating point
|
|
|
|
/// instructions.
|
2008-12-19 07:39:12 +01:00
|
|
|
|
2007-11-25 15:10:56 +01:00
|
|
|
/// @brief Attributes that only apply to function parameters.
|
2008-12-19 07:39:12 +01:00
|
|
|
const Attributes ParameterOnly = ByVal | Nest | StructRet | NoCapture;
|
2007-11-25 15:10:56 +01:00
|
|
|
|
2009-06-11 10:11:03 +02:00
|
|
|
/// @brief Attributes that may be applied to the function itself. These cannot
|
|
|
|
/// be used on return values or function parameters.
|
2008-10-03 23:11:02 +02:00
|
|
|
const Attributes FunctionOnly = NoReturn | NoUnwind | ReadNone | ReadOnly |
|
2009-06-05 00:05:33 +02:00
|
|
|
NoInline | AlwaysInline | OptimizeForSize | StackProtect | StackProtectReq |
|
2009-06-05 23:57:13 +02:00
|
|
|
NoRedZone | NoImplicitFloat;
|
2007-11-25 15:10:56 +01:00
|
|
|
|
2008-01-12 17:42:01 +01:00
|
|
|
/// @brief Parameter attributes that do not apply to vararg call arguments.
|
2008-02-19 22:38:47 +01:00
|
|
|
const Attributes VarArgsIncompatible = StructRet;
|
2008-01-11 23:36:48 +01:00
|
|
|
|
2007-11-25 15:10:56 +01:00
|
|
|
/// @brief Attributes that are mutually incompatible.
|
2008-10-02 01:41:25 +02:00
|
|
|
const Attributes MutuallyIncompatible[4] = {
|
2008-12-19 07:39:12 +01:00
|
|
|
ByVal | InReg | Nest | StructRet,
|
2007-11-25 15:10:56 +01:00
|
|
|
ZExt | SExt,
|
2008-10-02 01:41:25 +02:00
|
|
|
ReadNone | ReadOnly,
|
|
|
|
NoInline | AlwaysInline
|
2007-11-25 15:10:56 +01:00
|
|
|
};
|
|
|
|
|
2008-01-07 18:16:06 +01:00
|
|
|
/// @brief Which attributes cannot be applied to a type.
|
2008-03-12 18:45:29 +01:00
|
|
|
Attributes typeIncompatible(const Type *Ty);
|
2008-01-06 19:27:01 +01:00
|
|
|
|
2008-02-22 18:49:45 +01:00
|
|
|
/// This turns an int alignment (a power of 2, normally) into the
|
2008-09-24 01:03:40 +02:00
|
|
|
/// form used internally in Attributes.
|
|
|
|
inline Attributes constructAlignmentFromInt(unsigned i) {
|
2008-12-19 07:39:12 +01: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 18:49:45 +01:00
|
|
|
}
|
|
|
|
|
2008-12-31 09:41:38 +01: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-24 01:03:40 +02:00
|
|
|
/// The set of Attributes set in Attributes is converted to a
|
2008-03-12 18:45:29 +01:00
|
|
|
/// string of equivalent mnemonics. This is, presumably, for writing out
|
|
|
|
/// the mnemonics for the assembly writer.
|
2008-09-25 23:00:45 +02:00
|
|
|
/// @brief Convert attribute bits to text
|
2008-09-24 01:03:40 +02:00
|
|
|
std::string getAsString(Attributes Attrs);
|
2008-09-25 23:00:45 +02:00
|
|
|
} // end namespace Attribute
|
|
|
|
|
|
|
|
/// This is just a pair of values to associate a set of attributes
|
|
|
|
/// with an index.
|
|
|
|
struct AttributeWithIndex {
|
2008-09-24 01:03:40 +02:00
|
|
|
Attributes Attrs; ///< The attributes that are set, or'd together.
|
2008-03-12 18:45:29 +01:00
|
|
|
unsigned Index; ///< Index of the parameter for which the attributes apply.
|
2008-09-25 23:00:45 +02:00
|
|
|
///< Index 0 is used for return value attributes.
|
|
|
|
///< Index ~0U is used for function attributes.
|
2007-06-18 23:50:49 +02:00
|
|
|
|
2008-09-25 23:00:45 +02:00
|
|
|
static AttributeWithIndex get(unsigned Idx, Attributes Attrs) {
|
|
|
|
AttributeWithIndex P;
|
2008-03-12 18:45:29 +01:00
|
|
|
P.Index = Idx;
|
|
|
|
P.Attrs = Attrs;
|
2007-06-18 23:50:49 +02:00
|
|
|
return P;
|
|
|
|
}
|
2007-04-22 07:46:44 +02:00
|
|
|
};
|
2008-03-12 18:45:29 +01:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
2008-09-25 23:00:45 +02:00
|
|
|
// AttrListPtr Smart Pointer
|
2008-03-12 18:45:29 +01:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-09-24 02:29:49 +02:00
|
|
|
class AttributeListImpl;
|
2008-03-12 18:45:29 +01:00
|
|
|
|
2008-09-25 23:00:45 +02:00
|
|
|
/// AttrListPtr - This class manages the ref count for the opaque
|
2008-09-24 02:29:49 +02:00
|
|
|
/// AttributeListImpl object and provides accessors for it.
|
2008-09-25 23:00:45 +02: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 18:45:29 +01:00
|
|
|
public:
|
2008-09-25 23:00:45 +02:00
|
|
|
AttrListPtr() : AttrList(0) {}
|
|
|
|
AttrListPtr(const AttrListPtr &P);
|
|
|
|
const AttrListPtr &operator=(const AttrListPtr &RHS);
|
|
|
|
~AttrListPtr();
|
2008-03-12 18:45:29 +01:00
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
2008-09-25 23:00:45 +02:00
|
|
|
// Attribute List Construction and Mutation
|
2008-03-12 18:45:29 +01:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
|
2008-09-25 23:00:45 +02:00
|
|
|
/// get - Return a Attributes list with the specified parameter in it.
|
|
|
|
static AttrListPtr get(const AttributeWithIndex *Attr, unsigned NumAttrs);
|
2008-03-12 18:45:29 +01:00
|
|
|
|
2008-09-25 23:00:45 +02:00
|
|
|
/// get - Return a Attribute list with the parameters specified by the
|
2008-03-13 05:33:03 +01:00
|
|
|
/// consecutive random access iterator range.
|
2008-03-12 18:45:29 +01:00
|
|
|
template <typename Iter>
|
2008-09-25 23:00:45 +02:00
|
|
|
static AttrListPtr get(const Iter &I, const Iter &E) {
|
|
|
|
if (I == E) return AttrListPtr(); // Empty list.
|
2008-05-05 20:30:58 +02:00
|
|
|
return get(&*I, static_cast<unsigned>(E-I));
|
2008-03-12 18:45:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/// addAttr - Add the specified attribute at the specified index to this
|
2008-09-25 23:00:45 +02:00
|
|
|
/// attribute list. Since attribute lists are immutable, this
|
2008-03-12 18:45:29 +01:00
|
|
|
/// returns the new list.
|
2008-09-25 23:00:45 +02:00
|
|
|
AttrListPtr addAttr(unsigned Idx, Attributes Attrs) const;
|
2008-03-12 18:45:29 +01:00
|
|
|
|
|
|
|
/// removeAttr - Remove the specified attribute at the specified index from
|
2008-09-25 23:00:45 +02:00
|
|
|
/// this attribute list. Since attribute lists are immutable, this
|
2008-03-12 18:45:29 +01:00
|
|
|
/// returns the new list.
|
2008-09-25 23:00:45 +02:00
|
|
|
AttrListPtr removeAttr(unsigned Idx, Attributes Attrs) const;
|
2008-03-12 18:45:29 +01:00
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
2008-09-25 23:00:45 +02:00
|
|
|
// Attribute List Accessors
|
2008-03-12 18:45:29 +01:00
|
|
|
//===--------------------------------------------------------------------===//
|
2008-09-27 00:53:05 +02: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-16 00:55:03 +02:00
|
|
|
/// getFnAttributes - The function attributes are returned.
|
2008-09-27 00:53:05 +02:00
|
|
|
Attributes getFnAttributes() const {
|
2009-06-11 10:11:03 +02:00
|
|
|
return getAttributes(~0U);
|
2008-09-27 00:53:05 +02:00
|
|
|
}
|
2008-03-12 18:45:29 +01:00
|
|
|
|
|
|
|
/// paramHasAttr - Return true if the specified parameter index has the
|
|
|
|
/// specified attribute set.
|
2008-09-24 01:03:40 +02:00
|
|
|
bool paramHasAttr(unsigned Idx, Attributes Attr) const {
|
2008-09-25 23:00:45 +02:00
|
|
|
return getAttributes(Idx) & Attr;
|
2008-03-12 18:45:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/// getParamAlignment - Return the alignment for the specified function
|
|
|
|
/// parameter.
|
|
|
|
unsigned getParamAlignment(unsigned Idx) const {
|
2008-12-31 09:41:38 +01:00
|
|
|
return Attribute::getAlignmentFromAttrs(getAttributes(Idx));
|
2008-03-12 18:45:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/// hasAttrSomewhere - Return true if the specified attribute is set for at
|
|
|
|
/// least one parameter or for the return value.
|
2008-09-24 01:03:40 +02:00
|
|
|
bool hasAttrSomewhere(Attributes Attr) const;
|
2008-03-12 18:45:29 +01:00
|
|
|
|
2008-03-13 05:33:03 +01:00
|
|
|
/// operator==/!= - Provide equality predicates.
|
2008-09-25 23:00:45 +02:00
|
|
|
bool operator==(const AttrListPtr &RHS) const { return AttrList == RHS.AttrList; }
|
|
|
|
bool operator!=(const AttrListPtr &RHS) const { return AttrList != RHS.AttrList; }
|
2008-03-12 18:45:29 +01:00
|
|
|
|
|
|
|
void dump() const;
|
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
2008-09-25 23:00:45 +02:00
|
|
|
// Attribute List Introspection
|
2008-03-12 18:45:29 +01:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// getRawPointer - Return a raw pointer that uniquely identifies this
|
2008-09-25 23:00:45 +02:00
|
|
|
/// attribute list.
|
2008-03-12 18:45:29 +01:00
|
|
|
void *getRawPointer() const {
|
2008-09-25 23:00:45 +02:00
|
|
|
return AttrList;
|
2008-03-12 18:45:29 +01:00
|
|
|
}
|
|
|
|
|
2008-09-25 23:00:45 +02:00
|
|
|
// Attributes are stored as a dense set of slots, where there is one
|
2008-03-12 18:45:29 +01: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 23:00:45 +02:00
|
|
|
/// isEmpty - Return true if there are no attributes.
|
2008-03-12 18:45:29 +01:00
|
|
|
///
|
|
|
|
bool isEmpty() const {
|
2008-09-25 23:00:45 +02:00
|
|
|
return AttrList == 0;
|
2008-03-12 18:45:29 +01: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 23:00:45 +02: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 18:45:29 +01:00
|
|
|
|
|
|
|
private:
|
2008-09-25 23:00:45 +02:00
|
|
|
explicit AttrListPtr(AttributeListImpl *L);
|
2008-09-27 00:53:05 +02: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 18:45:29 +01:00
|
|
|
};
|
2007-04-22 07:46:44 +02:00
|
|
|
|
2007-04-08 16:46:50 +02:00
|
|
|
} // End llvm namespace
|
|
|
|
|
|
|
|
#endif
|