1 //===-- llvm/ParameterAttributes.h - Container for ParamAttrs ---*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by Reid Spencer and is distributed under the
6 // University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains the types necessary to represent the parameter attributes
11 // associated with functions and their calls.
13 // The implementations of these classes live in lib/VMCore/Function.cpp.
15 //===----------------------------------------------------------------------===//
17 #ifndef LLVM_PARAMETER_ATTRIBUTES_H
18 #define LLVM_PARAMETER_ATTRIBUTES_H
20 #include "llvm/ADT/SmallVector.h"
21 #include "llvm/ADT/FoldingSet.h"
25 /// Function parameters can have attributes to indicate how they should be
26 /// treated by optimizations and code generation. This enumeration lists the
27 /// attributes that can be associated with parameters or function results.
28 /// @brief Function parameter attributes.
32 None = 0, ///< No attributes have been set
33 ZExt = 1 << 0, ///< zero extended before/after call
34 SExt = 1 << 1, ///< sign extended before/after call
35 NoReturn = 1 << 2, ///< mark the function as not returning
36 InReg = 1 << 3, ///< force argument to be passed in register
37 StructRet = 1 << 4, ///< hidden pointer to structure to return
38 NoUnwind = 1 << 5 ///< Function doesn't unwind stack
43 /// This is just a pair of values to associate a set of parameter attributes
44 /// with a parameter index.
45 /// @brief ParameterAttributes with a parameter index.
46 struct ParamAttrsWithIndex {
47 uint16_t attrs; ///< The attributes that are set, |'d together
48 uint16_t index; ///< Index of the parameter for which the attributes apply
51 /// @brief A vector of attribute/index pairs.
52 typedef SmallVector<ParamAttrsWithIndex,4> ParamAttrsVector;
54 typedef ParamAttr::Attributes ParameterAttributes;
56 /// This class is used by Function and CallInst to represent the set of
57 /// parameter attributes used. It represents a list of pairs of uint16_t, one
58 /// for the parameter index, and one a set of ParameterAttributes bits.
59 /// Parameters that have no attributes are not present in the list. The list
60 /// may also be empty, but this doesn't occur in practice. The list constructs
61 /// as empty and is filled by the insert method. The list can be turned into
62 /// a string of mnemonics suitable for LLVM Assembly output. Various accessors
63 /// are provided to obtain information about the attributes.
64 /// @brief A List of ParameterAttributes.
65 class ParamAttrsList : public FoldingSetNode {
66 /// @name Construction
69 // ParamAttrsList is uniqued, thes should not be publicly available
70 void operator=(const ParamAttrsList &); // Do not implement
71 ParamAttrsList(const ParamAttrsList &); // Do not implement
72 ParamAttrsList(); // Do not implement
73 ~ParamAttrsList() {} // Not public!
75 /// @brief Construct an ParamAttrsList from a ParamAttrsVector
76 explicit ParamAttrsList(const ParamAttrsVector &attrVec) : attrs(attrVec) {}
79 /// This method ensures the uniqueness of ParamAttrsList instances. The
80 /// argument is a vector of attribute/index pairs as represented by the
81 /// ParamAttrsWithIndex structure. The vector is used in the construction of
82 /// the ParamAttrsList instance. If an instance with identical vector pairs
83 /// exists, it will be returned instead of creating a new instance.
84 /// @brief Get a ParamAttrsList instance.
85 static ParamAttrsList *get(const ParamAttrsVector &attrVec);
91 /// The parameter attributes for the \p indexth parameter are returned.
92 /// The 0th parameter refers to the return type of the function. Note that
93 /// the \p param_index is an index into the function's parameters, not an
94 /// index into this class's list of attributes. The result of getParamIndex
95 /// is always suitable input to this function.
96 /// @returns The all the ParameterAttributes for the \p indexth parameter
97 /// as a uint16_t of enumeration values OR'd together.
98 /// @brief Get the attributes for a parameter
99 uint16_t getParamAttrs(uint16_t param_index) const;
101 /// This checks to see if the \p ith function parameter has the parameter
102 /// attribute given by \p attr set.
103 /// @returns true if the parameter attribute is set
104 /// @brief Determine if a ParameterAttributes is set
105 bool paramHasAttr(uint16_t i, ParameterAttributes attr) const {
106 return getParamAttrs(i) & attr;
109 /// The set of ParameterAttributes set in Attributes is converted to a
110 /// string of equivalent mnemonics. This is, presumably, for writing out
111 /// the mnemonics for the assembly writer.
112 /// @brief Convert parameter attribute bits to text
113 static std::string getParamAttrsText(uint16_t Attributes);
115 /// The \p Indexth parameter attribute is converted to string.
116 /// @brief Get the text for the parmeter attributes for one parameter.
117 std::string getParamAttrsTextByIndex(uint16_t Index) const {
118 return getParamAttrsText(getParamAttrs(Index));
121 /// @brief Comparison operator for ParamAttrsList
122 bool operator < (const ParamAttrsList& that) const {
123 if (this->attrs.size() < that.attrs.size())
125 if (this->attrs.size() > that.attrs.size())
127 for (unsigned i = 0; i < attrs.size(); ++i) {
128 if (attrs[i].index < that.attrs[i].index)
130 if (attrs[i].index > that.attrs[i].index)
132 if (attrs[i].attrs < that.attrs[i].attrs)
134 if (attrs[i].attrs > that.attrs[i].attrs)
140 /// Returns the parameter index of a particular parameter attribute in this
141 /// list of attributes. Note that the attr_index is an index into this
142 /// class's list of attributes, not the index of a parameter. The result
143 /// is the index of the parameter. Clients generally should not use this
144 /// method. It is used internally by LLVM.
145 /// @brief Get a parameter index
146 uint16_t getParamIndex(unsigned attr_index) const {
147 return attrs[attr_index].index;
150 /// Determines how many parameter attributes are set in this ParamAttrsList.
151 /// This says nothing about how many parameters the function has. It also
152 /// says nothing about the highest parameter index that has attributes.
153 /// Clients generally should not use this method. It is used internally by
155 /// @returns the number of parameter attributes in this ParamAttrsList.
156 /// @brief Return the number of parameter attributes this type has.
157 unsigned size() const { return attrs.size(); }
160 /// @name Implementation Details
163 void Profile(FoldingSetNodeID &ID) const;
170 ParamAttrsVector attrs; ///< The list of attributes
174 } // End llvm namespace