llvm.org GIT mirror llvm / eaf42ab
s/ParameterAttributes/Attributes/g git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@56513 91177308-0d34-0410-b5e6-96231b3b80d8 Devang Patel 12 years ago
30 changed file(s) with 584 addition(s) and 592 deletion(s). Raw diff Collapse all Expand all
1414 #define LLVM_ARGUMENT_H
1515
1616 #include "llvm/Value.h"
17 #include "llvm/ParameterAttributes.h"
17 #include "llvm/Attributes.h"
1818 #include "llvm/ADT/ilist_node.h"
1919
2020 namespace llvm {
6060 bool hasStructRetAttr() const;
6161
6262 /// addAttr - Add a ParamAttr to an argument
63 void addAttr(ParameterAttributes);
63 void addAttr(Attributes);
6464
6565 /// removeAttr - Remove a ParamAttr from an argument
66 void removeAttr(ParameterAttributes);
66 void removeAttr(Attributes);
6767
6868 /// classof - Methods for support type inquiry through isa, cast, and
6969 /// dyn_cast:
0 //===-- llvm/Attributes.h - Container for ParamAttrs ---*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains the simple types necessary to represent the parameter
10 // attributes associated with functions and their calls.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_PARAMETER_ATTRIBUTES_H
15 #define LLVM_PARAMETER_ATTRIBUTES_H
16
17 #include
18
19 namespace llvm {
20 class Type;
21
22 /// Attributes - A bitset of attributes for a parameter.
23 typedef unsigned Attributes;
24
25 namespace ParamAttr {
26
27 /// Function parameters and results can have attributes to indicate how they
28 /// should be treated by optimizations and code generation. This enumeration
29 /// lists the attributes that can be associated with parameters or function
30 /// results.
31 /// @brief Function parameter attributes.
32
33 const Attributes None = 0; ///< No attributes have been set
34 const Attributes ZExt = 1<<0; ///< Zero extended before/after call
35 const Attributes SExt = 1<<1; ///< Sign extended before/after call
36 const Attributes NoReturn = 1<<2; ///< Mark the function as not returning
37 const Attributes InReg = 1<<3; ///< Force argument to be passed in register
38 const Attributes StructRet = 1<<4; ///< Hidden pointer to structure to return
39 const Attributes NoUnwind = 1<<5; ///< Function doesn't unwind stack
40 const Attributes NoAlias = 1<<6; ///< Considered to not alias after call
41 const Attributes ByVal = 1<<7; ///< Pass structure by value
42 const Attributes Nest = 1<<8; ///< Nested function static chain
43 const Attributes ReadNone = 1<<9; ///< Function does not access memory
44 const Attributes ReadOnly = 1<<10; ///< Function only reads from memory
45 const Attributes Alignment = 0xffff<<16; ///< Alignment of parameter (16 bits)
46 // 0 = unknown, else in clear (not log)
47
48 /// Function notes are implemented as attributes stored at index ~0 in
49 /// parameter attribute list.
50 const Attributes FN_NOTE_None = 0;
51 const Attributes FN_NOTE_NoInline = 1<<0; // inline=never
52 const Attributes FN_NOTE_AlwaysInline = 1<<1; // inline=always
53 const Attributes FN_NOTE_OptimizeForSize = 1<<2; // opt_size
54
55 /// @brief Attributes that only apply to function parameters.
56 const Attributes ParameterOnly = ByVal | Nest | StructRet;
57
58 /// @brief Attributes that only apply to function return values.
59 const Attributes ReturnOnly = NoReturn | NoUnwind | ReadNone | ReadOnly;
60
61 /// @brief Parameter attributes that do not apply to vararg call arguments.
62 const Attributes VarArgsIncompatible = StructRet;
63
64 /// @brief Attributes that are mutually incompatible.
65 const Attributes MutuallyIncompatible[3] = {
66 ByVal | InReg | Nest | StructRet,
67 ZExt | SExt,
68 ReadNone | ReadOnly
69 };
70
71 /// @brief Which attributes cannot be applied to a type.
72 Attributes typeIncompatible(const Type *Ty);
73
74 /// This turns an int alignment (a power of 2, normally) into the
75 /// form used internally in Attributes.
76 inline Attributes constructAlignmentFromInt(unsigned i) {
77 return (i << 16);
78 }
79
80 /// The set of Attributes set in Attributes is converted to a
81 /// string of equivalent mnemonics. This is, presumably, for writing out
82 /// the mnemonics for the assembly writer.
83 /// @brief Convert parameter attribute bits to text
84 std::string getAsString(Attributes Attrs);
85 } // end namespace ParamAttr
86
87
88 /// This is just a pair of values to associate a set of parameter attributes
89 /// with a parameter index.
90 struct ParamAttrsWithIndex {
91 Attributes Attrs; ///< The attributes that are set, or'd together.
92 unsigned Index; ///< Index of the parameter for which the attributes apply.
93
94 static ParamAttrsWithIndex get(unsigned Idx, Attributes Attrs) {
95 ParamAttrsWithIndex P;
96 P.Index = Idx;
97 P.Attrs = Attrs;
98 return P;
99 }
100 };
101
102 //===----------------------------------------------------------------------===//
103 // PAListPtr Smart Pointer
104 //===----------------------------------------------------------------------===//
105
106 class ParamAttributeListImpl;
107
108 /// PAListPtr - This class manages the ref count for the opaque
109 /// ParamAttributeListImpl object and provides accessors for it.
110 class PAListPtr {
111 /// PAList - The parameter attributes that we are managing. This can be null
112 /// to represent the empty parameter attributes list.
113 ParamAttributeListImpl *PAList;
114 public:
115 PAListPtr() : PAList(0) {}
116 PAListPtr(const PAListPtr &P);
117 const PAListPtr &operator=(const PAListPtr &RHS);
118 ~PAListPtr();
119
120 //===--------------------------------------------------------------------===//
121 // Parameter Attribute List Construction and Mutation
122 //===--------------------------------------------------------------------===//
123
124 /// get - Return a ParamAttrs list with the specified parameter in it.
125 static PAListPtr get(const ParamAttrsWithIndex *Attr, unsigned NumAttrs);
126
127 /// get - Return a ParamAttr list with the parameters specified by the
128 /// consecutive random access iterator range.
129 template
130 static PAListPtr get(const Iter &I, const Iter &E) {
131 if (I == E) return PAListPtr(); // Empty list.
132 return get(&*I, static_cast(E-I));
133 }
134
135 /// addAttr - Add the specified attribute at the specified index to this
136 /// attribute list. Since parameter attribute lists are immutable, this
137 /// returns the new list.
138 PAListPtr addAttr(unsigned Idx, Attributes Attrs) const;
139
140 /// removeAttr - Remove the specified attribute at the specified index from
141 /// this attribute list. Since parameter attribute lists are immutable, this
142 /// returns the new list.
143 PAListPtr removeAttr(unsigned Idx, Attributes Attrs) const;
144
145 //===--------------------------------------------------------------------===//
146 // Parameter Attribute List Accessors
147 //===--------------------------------------------------------------------===//
148
149 /// getParamAttrs - The parameter attributes for the specified parameter are
150 /// returned. Parameters for the result are denoted with Idx = 0.
151 Attributes getParamAttrs(unsigned Idx) const;
152
153 /// paramHasAttr - Return true if the specified parameter index has the
154 /// specified attribute set.
155 bool paramHasAttr(unsigned Idx, Attributes Attr) const {
156 return getParamAttrs(Idx) & Attr;
157 }
158
159 /// getParamAlignment - Return the alignment for the specified function
160 /// parameter.
161 unsigned getParamAlignment(unsigned Idx) const {
162 return (getParamAttrs(Idx) & ParamAttr::Alignment) >> 16;
163 }
164
165 /// hasAttrSomewhere - Return true if the specified attribute is set for at
166 /// least one parameter or for the return value.
167 bool hasAttrSomewhere(Attributes Attr) const;
168
169 /// operator==/!= - Provide equality predicates.
170 bool operator==(const PAListPtr &RHS) const { return PAList == RHS.PAList; }
171 bool operator!=(const PAListPtr &RHS) const { return PAList != RHS.PAList; }
172
173 void dump() const;
174
175 //===--------------------------------------------------------------------===//
176 // Parameter Attribute List Introspection
177 //===--------------------------------------------------------------------===//
178
179 /// getRawPointer - Return a raw pointer that uniquely identifies this
180 /// parameter attribute list.
181 void *getRawPointer() const {
182 return PAList;
183 }
184
185 // Parameter attributes are stored as a dense set of slots, where there is one
186 // slot for each argument that has an attribute. This allows walking over the
187 // dense set instead of walking the sparse list of attributes.
188
189 /// isEmpty - Return true if no parameters have an attribute.
190 ///
191 bool isEmpty() const {
192 return PAList == 0;
193 }
194
195 /// getNumSlots - Return the number of slots used in this attribute list.
196 /// This is the number of arguments that have an attribute set on them
197 /// (including the function itself).
198 unsigned getNumSlots() const;
199
200 /// getSlot - Return the ParamAttrsWithIndex at the specified slot. This
201 /// holds a parameter number plus a set of attributes.
202 const ParamAttrsWithIndex &getSlot(unsigned Slot) const;
203
204 private:
205 explicit PAListPtr(ParamAttributeListImpl *L);
206 };
207
208 } // End llvm namespace
209
210 #endif
2121 #include "llvm/BasicBlock.h"
2222 #include "llvm/Argument.h"
2323 #include "llvm/Support/Annotation.h"
24 #include "llvm/ParameterAttributes.h"
24 #include "llvm/Attributes.h"
2525
2626 namespace llvm {
2727
149149
150150
151151 /// hasNote - Return true if this function has given note.
152 bool hasNote(ParameterAttributes N) const {
152 bool hasNote(Attributes N) const {
153153 // Notes are stored at ~0 index in parameter attribute list
154154 return (!isDeclaration() && paramHasAttr(~0, N));
155155 }
156156
157157 /// setNotes - Set notes for this function
158158 ///
159 void setNotes(const ParameterAttributes N) {
159 void setNotes(const Attributes N) {
160160 // Notes are stored at ~0 index in parameter attribute list
161161 addParamAttr(~0, N);
162162 }
169169 void clearGC();
170170
171171 /// @brief Determine whether the function has the given attribute.
172 bool paramHasAttr(unsigned i, ParameterAttributes attr) const {
172 bool paramHasAttr(unsigned i, Attributes attr) const {
173173 return ParamAttrs.paramHasAttr(i, attr);
174174 }
175175
176176 /// addParamAttr - adds the attribute to the list of attributes.
177 void addParamAttr(unsigned i, ParameterAttributes attr);
177 void addParamAttr(unsigned i, Attributes attr);
178178
179179 /// removeParamAttr - removes the attribute from the list of attributes.
180 void removeParamAttr(unsigned i, ParameterAttributes attr);
180 void removeParamAttr(unsigned i, Attributes attr);
181181
182182 /// @brief Extract the alignment for a call or parameter (0=unknown).
183183 unsigned getParamAlignment(unsigned i) const {
1919
2020 #include "llvm/InstrTypes.h"
2121 #include "llvm/DerivedTypes.h"
22 #include "llvm/ParameterAttributes.h"
22 #include "llvm/Attributes.h"
2323 #include "llvm/BasicBlock.h"
2424 #include "llvm/ADT/SmallVector.h"
2525
10801080 void setParamAttrs(const PAListPtr &Attrs) { ParamAttrs = Attrs; }
10811081
10821082 /// addParamAttr - adds the attribute to the list of attributes.
1083 void addParamAttr(unsigned i, ParameterAttributes attr);
1083 void addParamAttr(unsigned i, Attributes attr);
10841084
10851085 /// removeParamAttr - removes the attribute from the list of attributes.
1086 void removeParamAttr(unsigned i, ParameterAttributes attr);
1086 void removeParamAttr(unsigned i, Attributes attr);
10871087
10881088 /// @brief Determine whether the call or the callee has the given attribute.
10891089 bool paramHasAttr(unsigned i, unsigned attr) const;
24392439 void setParamAttrs(const PAListPtr &Attrs) { ParamAttrs = Attrs; }
24402440
24412441 /// @brief Determine whether the call or the callee has the given attribute.
2442 bool paramHasAttr(unsigned i, ParameterAttributes attr) const;
2442 bool paramHasAttr(unsigned i, Attributes attr) const;
24432443
24442444 /// addParamAttr - adds the attribute to the list of attributes.
2445 void addParamAttr(unsigned i, ParameterAttributes attr);
2445 void addParamAttr(unsigned i, Attributes attr);
24462446
24472447 /// removeParamAttr - removes the attribute from the list of attributes.
2448 void removeParamAttr(unsigned i, ParameterAttributes attr);
2448 void removeParamAttr(unsigned i, Attributes attr);
24492449
24502450 /// @brief Extract the alignment for a call or parameter (0=unknown).
24512451 unsigned getParamAlignment(unsigned i) const {
+0
-212
include/llvm/ParameterAttributes.h less more
None //===-- llvm/ParameterAttributes.h - Container for ParamAttrs ---*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains the simple types necessary to represent the parameter
10 // attributes associated with functions and their calls.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_PARAMETER_ATTRIBUTES_H
15 #define LLVM_PARAMETER_ATTRIBUTES_H
16
17 #include
18
19 namespace llvm {
20 class Type;
21
22 /// ParameterAttributes - A bitset of attributes for a parameter.
23 typedef unsigned ParameterAttributes;
24
25 namespace ParamAttr {
26
27 /// Function parameters and results can have attributes to indicate how they
28 /// should be treated by optimizations and code generation. This enumeration
29 /// lists the attributes that can be associated with parameters or function
30 /// results.
31 /// @brief Function parameter attributes.
32 typedef ParameterAttributes Attributes;
33
34 const Attributes None = 0; ///< No attributes have been set
35 const Attributes ZExt = 1<<0; ///< Zero extended before/after call
36 const Attributes SExt = 1<<1; ///< Sign extended before/after call
37 const Attributes NoReturn = 1<<2; ///< Mark the function as not returning
38 const Attributes InReg = 1<<3; ///< Force argument to be passed in register
39 const Attributes StructRet = 1<<4; ///< Hidden pointer to structure to return
40 const Attributes NoUnwind = 1<<5; ///< Function doesn't unwind stack
41 const Attributes NoAlias = 1<<6; ///< Considered to not alias after call
42 const Attributes ByVal = 1<<7; ///< Pass structure by value
43 const Attributes Nest = 1<<8; ///< Nested function static chain
44 const Attributes ReadNone = 1<<9; ///< Function does not access memory
45 const Attributes ReadOnly = 1<<10; ///< Function only reads from memory
46 const Attributes Alignment = 0xffff<<16; ///< Alignment of parameter (16 bits)
47 // 0 = unknown, else in clear (not log)
48
49 /// Function notes are implemented as attributes stored at index ~0 in
50 /// parameter attribute list.
51 const Attributes FN_NOTE_None = 0;
52 const Attributes FN_NOTE_NoInline = 1<<0; // inline=never
53 const Attributes FN_NOTE_AlwaysInline = 1<<1; // inline=always
54 const Attributes FN_NOTE_OptimizeForSize = 1<<2; // opt_size
55
56 /// @brief Attributes that only apply to function parameters.
57 const Attributes ParameterOnly = ByVal | Nest | StructRet;
58
59 /// @brief Attributes that only apply to function return values.
60 const Attributes ReturnOnly = NoReturn | NoUnwind | ReadNone | ReadOnly;
61
62 /// @brief Parameter attributes that do not apply to vararg call arguments.
63 const Attributes VarArgsIncompatible = StructRet;
64
65 /// @brief Attributes that are mutually incompatible.
66 const Attributes MutuallyIncompatible[3] = {
67 ByVal | InReg | Nest | StructRet,
68 ZExt | SExt,
69 ReadNone | ReadOnly
70 };
71
72 /// @brief Which attributes cannot be applied to a type.
73 Attributes typeIncompatible(const Type *Ty);
74
75 /// This turns an int alignment (a power of 2, normally) into the
76 /// form used internally in ParameterAttributes.
77 inline ParamAttr::Attributes constructAlignmentFromInt(unsigned i) {
78 return (i << 16);
79 }
80
81 /// The set of ParameterAttributes set in Attributes is converted to a
82 /// string of equivalent mnemonics. This is, presumably, for writing out
83 /// the mnemonics for the assembly writer.
84 /// @brief Convert parameter attribute bits to text
85 std::string getAsString(ParameterAttributes Attrs);
86 } // end namespace ParamAttr
87
88
89 /// This is just a pair of values to associate a set of parameter attributes
90 /// with a parameter index.
91 struct ParamAttrsWithIndex {
92 ParameterAttributes Attrs; ///< The attributes that are set, or'd together.
93 unsigned Index; ///< Index of the parameter for which the attributes apply.
94
95 static ParamAttrsWithIndex get(unsigned Idx, ParameterAttributes Attrs) {
96 ParamAttrsWithIndex P;
97 P.Index = Idx;
98 P.Attrs = Attrs;
99 return P;
100 }
101 };
102
103 //===----------------------------------------------------------------------===//
104 // PAListPtr Smart Pointer
105 //===----------------------------------------------------------------------===//
106
107 class ParamAttributeListImpl;
108
109 /// PAListPtr - This class manages the ref count for the opaque
110 /// ParamAttributeListImpl object and provides accessors for it.
111 class PAListPtr {
112 /// PAList - The parameter attributes that we are managing. This can be null
113 /// to represent the empty parameter attributes list.
114 ParamAttributeListImpl *PAList;
115 public:
116 PAListPtr() : PAList(0) {}
117 PAListPtr(const PAListPtr &P);
118 const PAListPtr &operator=(const PAListPtr &RHS);
119 ~PAListPtr();
120
121 //===--------------------------------------------------------------------===//
122 // Parameter Attribute List Construction and Mutation
123 //===--------------------------------------------------------------------===//
124
125 /// get - Return a ParamAttrs list with the specified parameter in it.
126 static PAListPtr get(const ParamAttrsWithIndex *Attr, unsigned NumAttrs);
127
128 /// get - Return a ParamAttr list with the parameters specified by the
129 /// consecutive random access iterator range.
130 template
131 static PAListPtr get(const Iter &I, const Iter &E) {
132 if (I == E) return PAListPtr(); // Empty list.
133 return get(&*I, static_cast(E-I));
134 }
135
136 /// addAttr - Add the specified attribute at the specified index to this
137 /// attribute list. Since parameter attribute lists are immutable, this
138 /// returns the new list.
139 PAListPtr addAttr(unsigned Idx, ParameterAttributes Attrs) const;
140
141 /// removeAttr - Remove the specified attribute at the specified index from
142 /// this attribute list. Since parameter attribute lists are immutable, this
143 /// returns the new list.
144 PAListPtr removeAttr(unsigned Idx, ParameterAttributes Attrs) const;
145
146 //===--------------------------------------------------------------------===//
147 // Parameter Attribute List Accessors
148 //===--------------------------------------------------------------------===//
149
150 /// getParamAttrs - The parameter attributes for the specified parameter are
151 /// returned. Parameters for the result are denoted with Idx = 0.
152 ParameterAttributes getParamAttrs(unsigned Idx) const;
153
154 /// paramHasAttr - Return true if the specified parameter index has the
155 /// specified attribute set.
156 bool paramHasAttr(unsigned Idx, ParameterAttributes Attr) const {
157 return getParamAttrs(Idx) & Attr;
158 }
159
160 /// getParamAlignment - Return the alignment for the specified function
161 /// parameter.
162 unsigned getParamAlignment(unsigned Idx) const {
163 return (getParamAttrs(Idx) & ParamAttr::Alignment) >> 16;
164 }
165
166 /// hasAttrSomewhere - Return true if the specified attribute is set for at
167 /// least one parameter or for the return value.
168 bool hasAttrSomewhere(ParameterAttributes Attr) const;
169
170 /// operator==/!= - Provide equality predicates.
171 bool operator==(const PAListPtr &RHS) const { return PAList == RHS.PAList; }
172 bool operator!=(const PAListPtr &RHS) const { return PAList != RHS.PAList; }
173
174 void dump() const;
175
176 //===--------------------------------------------------------------------===//
177 // Parameter Attribute List Introspection
178 //===--------------------------------------------------------------------===//
179
180 /// getRawPointer - Return a raw pointer that uniquely identifies this
181 /// parameter attribute list.
182 void *getRawPointer() const {
183 return PAList;
184 }
185
186 // Parameter attributes are stored as a dense set of slots, where there is one
187 // slot for each argument that has an attribute. This allows walking over the
188 // dense set instead of walking the sparse list of attributes.
189
190 /// isEmpty - Return true if no parameters have an attribute.
191 ///
192 bool isEmpty() const {
193 return PAList == 0;
194 }
195
196 /// getNumSlots - Return the number of slots used in this attribute list.
197 /// This is the number of arguments that have an attribute set on them
198 /// (including the function itself).
199 unsigned getNumSlots() const;
200
201 /// getSlot - Return the ParamAttrsWithIndex at the specified slot. This
202 /// holds a parameter number plus a set of attributes.
203 const ParamAttrsWithIndex &getSlot(unsigned Slot) const;
204
205 private:
206 explicit PAListPtr(ParamAttributeListImpl *L);
207 };
208
209 } // End llvm namespace
210
211 #endif
2121
2222 #include "llvm/Instruction.h"
2323 #include "llvm/BasicBlock.h"
24 #include "llvm/ParameterAttributes.h"
24 #include "llvm/Attributes.h"
2525
2626 namespace llvm {
2727
6767 void setParamAttrs(const PAListPtr &PAL);
6868
6969 /// paramHasAttr - whether the call or the callee has the given attribute.
70 bool paramHasAttr(uint16_t i, ParameterAttributes attr) const;
70 bool paramHasAttr(uint16_t i, Attributes attr) const;
7171
7272 /// @brief Extract the alignment for a call or parameter (0=unknown).
7373 uint16_t getParamAlignment(uint16_t i) const;
1717 #include "llvm/Constants.h"
1818 #include "llvm/DerivedTypes.h"
1919 #include "llvm/Function.h"
20 #include "llvm/ParameterAttributes.h"
2120 #include "llvm/GlobalVariable.h"
2221 #include "llvm/Instructions.h"
2322 #include "llvm/IntrinsicInst.h"
1616
1717 #include "llvm/Constants.h"
1818 #include "llvm/DerivedTypes.h"
19 #include "llvm/ParameterAttributes.h"
19 #include "llvm/Attributes.h"
2020 #include "llvm/Function.h"
2121 #include "llvm/Instructions.h"
2222 #include "llvm/Assembly/Parser.h"
231231
232232 struct TypeWithAttrs {
233233 llvm::PATypeHolder *Ty;
234 ParameterAttributes Attrs;
234 Attributes Attrs;
235235 };
236236
237237 typedef std::vector TypeWithAttrsList;
238238
239239 struct ArgListEntry {
240 ParameterAttributes Attrs;
240 Attributes Attrs;
241241 llvm::PATypeHolder *Ty;
242242 std::string *Name;
243243 };
246246
247247 struct ParamListEntry {
248248 Value *Val;
249 ParameterAttributes Attrs;
249 Attributes Attrs;
250250 };
251251
252252 typedef std::vector ParamList;
1414 #define BITCODE_READER_H
1515
1616 #include "llvm/ModuleProvider.h"
17 #include "llvm/ParameterAttributes.h"
17 #include "llvm/Attributes.h"
1818 #include "llvm/Type.h"
1919 #include "llvm/OperandTraits.h"
2020 #include "llvm/Bitcode/BitstreamReader.h"
1414 #define VALUE_ENUMERATOR_H
1515
1616 #include "llvm/ADT/DenseMap.h"
17 #include "llvm/ParameterAttributes.h"
17 #include "llvm/Attributes.h"
1818 #include
1919
2020 namespace llvm {
2424 #include "llvm/Instructions.h"
2525 #include "llvm/Intrinsics.h"
2626 #include "llvm/IntrinsicInst.h"
27 #include "llvm/ParameterAttributes.h"
2827 #include "llvm/CodeGen/FastISel.h"
2928 #include "llvm/CodeGen/GCStrategy.h"
3029 #include "llvm/CodeGen/GCMetadata.h"
2424 #include "llvm/Instructions.h"
2525 #include "llvm/Intrinsics.h"
2626 #include "llvm/IntrinsicInst.h"
27 #include "llvm/ParameterAttributes.h"
2827 #include "llvm/CodeGen/FastISel.h"
2928 #include "llvm/CodeGen/GCStrategy.h"
3029 #include "llvm/CodeGen/GCMetadata.h"
1515 #include "llvm/Constants.h"
1616 #include "llvm/DerivedTypes.h"
1717 #include "llvm/Instructions.h"
18 #include "llvm/ParameterAttributes.h"
1918 #include "llvm/CodeGen/IntrinsicLowering.h"
2019 #include "llvm/Support/GetElementPtrTypeIterator.h"
2120 #include "llvm/ADT/APInt.h"
437437 Out << "ParamAttrsWithIndex PAWI;"; nl(Out);
438438 for (unsigned i = 0; i < PAL.getNumSlots(); ++i) {
439439 uint16_t index = PAL.getSlot(i).Index;
440 ParameterAttributes attrs = PAL.getSlot(i).Attrs;
440 Attributes attrs = PAL.getSlot(i).Attrs;
441441 Out << "PAWI.Index = " << index << "; PAWI.Attrs = 0 ";
442442 if (attrs & ParamAttr::SExt)
443443 Out << " | ParamAttr::SExt";
1515 #include "llvm/DerivedTypes.h"
1616 #include "llvm/Intrinsics.h"
1717 #include "llvm/IntrinsicInst.h"
18 #include "llvm/ParameterAttributes.h"
1918 #include "llvm/TypeSymbolTable.h"
2019 #include "llvm/Analysis/ConstantsScanner.h"
2120 #include "llvm/Support/CallSite.h"
2828 #include "llvm/Constants.h"
2929 #include "llvm/Function.h"
3030 #include "llvm/Intrinsics.h"
31 #include "llvm/ParameterAttributes.h"
3231 #include "llvm/Support/MathExtras.h"
3332 #include "llvm/Target/TargetOptions.h"
3433 #include "llvm/Support/CommandLine.h"
507507 const PAListPtr &PAL = F->getParamAttrs();
508508
509509 // Add any return attributes.
510 if (ParameterAttributes attrs = PAL.getParamAttrs(0))
510 if (Attributes attrs = PAL.getParamAttrs(0))
511511 ParamAttrsVec.push_back(ParamAttrsWithIndex::get(0, attrs));
512512
513513 // First, determine the new argument list
524524 } else if (!ArgsToPromote.count(I)) {
525525 // Unchanged argument
526526 Params.push_back(I->getType());
527 if (ParameterAttributes attrs = PAL.getParamAttrs(ArgIndex))
527 if (Attributes attrs = PAL.getParamAttrs(ArgIndex))
528528 ParamAttrsVec.push_back(ParamAttrsWithIndex::get(Params.size(), attrs));
529529 } else if (I->use_empty()) {
530530 // Dead argument (which are always marked as promotable)
620620 const PAListPtr &CallPAL = CS.getParamAttrs();
621621
622622 // Add any return attributes.
623 if (ParameterAttributes attrs = CallPAL.getParamAttrs(0))
623 if (Attributes attrs = CallPAL.getParamAttrs(0))
624624 ParamAttrsVec.push_back(ParamAttrsWithIndex::get(0, attrs));
625625
626626 // Loop over the operands, inserting GEP and loads in the caller as
632632 if (!ArgsToPromote.count(I) && !ByValArgsToTransform.count(I)) {
633633 Args.push_back(*AI); // Unmodified argument
634634
635 if (ParameterAttributes Attrs = CallPAL.getParamAttrs(ArgIndex))
635 if (Attributes Attrs = CallPAL.getParamAttrs(ArgIndex))
636636 ParamAttrsVec.push_back(ParamAttrsWithIndex::get(Args.size(), Attrs));
637637
638638 } else if (ByValArgsToTransform.count(I)) {
687687 // Push any varargs arguments on the list
688688 for (; AI != CS.arg_end(); ++AI, ++ArgIndex) {
689689 Args.push_back(*AI);
690 if (ParameterAttributes Attrs = CallPAL.getParamAttrs(ArgIndex))
690 if (Attributes Attrs = CallPAL.getParamAttrs(ArgIndex))
691691 ParamAttrsVec.push_back(ParamAttrsWithIndex::get(Args.size(), Attrs));
692692 }
693693
592592 const PAListPtr &PAL = F->getParamAttrs();
593593
594594 // The existing function return attributes.
595 ParameterAttributes RAttrs = PAL.getParamAttrs(0);
595 Attributes RAttrs = PAL.getParamAttrs(0);
596596
597597
598598 // Find out the new return value.
677677
678678 // Get the original parameter attributes (skipping the first one, that is
679679 // for the return value.
680 if (ParameterAttributes Attrs = PAL.getParamAttrs(i + 1))
680 if (Attributes Attrs = PAL.getParamAttrs(i + 1))
681681 ParamAttrsVec.push_back(ParamAttrsWithIndex::get(Params.size(), Attrs));
682682 } else {
683683 ++NumArgumentsEliminated;
729729 const PAListPtr &CallPAL = CS.getParamAttrs();
730730
731731 // The call return attributes.
732 ParameterAttributes RAttrs = CallPAL.getParamAttrs(0);
732 Attributes RAttrs = CallPAL.getParamAttrs(0);
733733 // Adjust in case the function was changed to return void.
734734 RAttrs &= ~ParamAttr::typeIncompatible(NF->getReturnType());
735735 if (RAttrs)
745745 if (ArgAlive[i]) {
746746 Args.push_back(*I);
747747 // Get original parameter attributes, but skip return attributes.
748 if (ParameterAttributes Attrs = CallPAL.getParamAttrs(i + 1))
748 if (Attributes Attrs = CallPAL.getParamAttrs(i + 1))
749749 ParamAttrsVec.push_back(ParamAttrsWithIndex::get(Args.size(), Attrs));
750750 }
751751
755755 // Push any varargs arguments on the list. Don't forget their attributes.
756756 for (CallSite::arg_iterator E = CS.arg_end(); I != E; ++I, ++i) {
757757 Args.push_back(*I);
758 if (ParameterAttributes Attrs = CallPAL.getParamAttrs(i + 1))
758 if (Attributes Attrs = CallPAL.getParamAttrs(i + 1))
759759 ParamAttrsVec.push_back(ParamAttrsWithIndex::get(Args.size(), Attrs));
760760 }
761761
124124 // If the SCC doesn't unwind or doesn't throw, note this fact.
125125 if (!SCCMightUnwind || !SCCMightReturn)
126126 for (unsigned i = 0, e = SCC.size(); i != e; ++i) {
127 ParameterAttributes NewAttributes = ParamAttr::None;
127 Attributes NewAttributes = ParamAttr::None;
128128
129129 if (!SCCMightUnwind)
130130 NewAttributes |= ParamAttr::NoUnwind;
209209 const PAListPtr &PAL = F->getParamAttrs();
210210
211211 // Add any return attributes.
212 if (ParameterAttributes attrs = PAL.getParamAttrs(0))
212 if (Attributes attrs = PAL.getParamAttrs(0))
213213 ParamAttrsVec.push_back(ParamAttrsWithIndex::get(0, attrs));
214214
215215 // Skip first argument.
220220 unsigned ParamIndex = 2;
221221 while (I != E) {
222222 Params.push_back(I->getType());
223 if (ParameterAttributes Attrs = PAL.getParamAttrs(ParamIndex))
223 if (Attributes Attrs = PAL.getParamAttrs(ParamIndex))
224224 ParamAttrsVec.push_back(ParamAttrsWithIndex::get(ParamIndex - 1, Attrs));
225225 ++I;
226226 ++ParamIndex;
263263
264264 const PAListPtr &PAL = F->getParamAttrs();
265265 // Add any return attributes.
266 if (ParameterAttributes attrs = PAL.getParamAttrs(0))
266 if (Attributes attrs = PAL.getParamAttrs(0))
267267 ArgAttrsVec.push_back(ParamAttrsWithIndex::get(0, attrs));
268268
269269 // Copy arguments, however skip first one.
275275 unsigned ParamIndex = 2;
276276 while (AI != AE) {
277277 Args.push_back(*AI);
278 if (ParameterAttributes Attrs = PAL.getParamAttrs(ParamIndex))
278 if (Attributes Attrs = PAL.getParamAttrs(ParamIndex))
279279 ArgAttrsVec.push_back(ParamAttrsWithIndex::get(ParamIndex - 1, Attrs));
280280 ++ParamIndex;
281281 ++AI;
91269126 return false; // Cannot transform this return value.
91279127
91289128 if (!CallerPAL.isEmpty() && !Caller->use_empty()) {
9129 ParameterAttributes RAttrs = CallerPAL.getParamAttrs(0);
9129 Attributes RAttrs = CallerPAL.getParamAttrs(0);
91309130 if (RAttrs & ParamAttr::typeIncompatible(NewRetTy))
91319131 return false; // Attribute not compatible with transformed value.
91329132 }
91799179 for (unsigned i = CallerPAL.getNumSlots(); i; --i) {
91809180 if (CallerPAL.getSlot(i - 1).Index <= FT->getNumParams())
91819181 break;
9182 ParameterAttributes PAttrs = CallerPAL.getSlot(i - 1).Attrs;
9182 Attributes PAttrs = CallerPAL.getSlot(i - 1).Attrs;
91839183 if (PAttrs & ParamAttr::VarArgsIncompatible)
91849184 return false;
91859185 }
91929192 attrVec.reserve(NumCommonArgs);
91939193
91949194 // Get any return attributes.
9195 ParameterAttributes RAttrs = CallerPAL.getParamAttrs(0);
9195 Attributes RAttrs = CallerPAL.getParamAttrs(0);
91969196
91979197 // If the return value is not being used, the type may not be compatible
91989198 // with the existing attributes. Wipe out any problematic attributes.
92159215 }
92169216
92179217 // Add any parameter attributes.
9218 if (ParameterAttributes PAttrs = CallerPAL.getParamAttrs(i + 1))
9218 if (Attributes PAttrs = CallerPAL.getParamAttrs(i + 1))
92199219 attrVec.push_back(ParamAttrsWithIndex::get(i + 1, PAttrs));
92209220 }
92219221
92459245 }
92469246
92479247 // Add any parameter attributes.
9248 if (ParameterAttributes PAttrs = CallerPAL.getParamAttrs(i + 1))
9248 if (Attributes PAttrs = CallerPAL.getParamAttrs(i + 1))
92499249 attrVec.push_back(ParamAttrsWithIndex::get(i + 1, PAttrs));
92509250 }
92519251 }
93289328 if (!NestAttrs.isEmpty()) {
93299329 unsigned NestIdx = 1;
93309330 const Type *NestTy = 0;
9331 ParameterAttributes NestAttr = ParamAttr::None;
9331 Attributes NestAttr = ParamAttr::None;
93329332
93339333 // Look for a parameter marked with the 'nest' attribute.
93349334 for (FunctionType::param_iterator I = NestFTy->param_begin(),
93529352 // mean appending it. Likewise for attributes.
93539353
93549354 // Add any function result attributes.
9355 if (ParameterAttributes Attr = Attrs.getParamAttrs(0))
9355 if (Attributes Attr = Attrs.getParamAttrs(0))
93569356 NewAttrs.push_back(ParamAttrsWithIndex::get(0, Attr));
93579357
93589358 {
93739373
93749374 // Add the original argument and attributes.
93759375 NewArgs.push_back(*I);
9376 if (ParameterAttributes Attr = Attrs.getParamAttrs(Idx))
9376 if (Attributes Attr = Attrs.getParamAttrs(Idx))
93779377 NewAttrs.push_back
93789378 (ParamAttrsWithIndex::get(Idx + (Idx >= NestIdx), Attr));
93799379
1515 #include "llvm/Transforms/Scalar.h"
1616 #include "llvm/IntrinsicInst.h"
1717 #include "llvm/Instructions.h"
18 #include "llvm/ParameterAttributes.h"
1918 #include "llvm/ADT/SmallVector.h"
2019 #include "llvm/ADT/Statistic.h"
2120 #include "llvm/Analysis/Dominators.h"
2626 #include "llvm/Constants.h"
2727 #include "llvm/Instructions.h"
2828 #include "llvm/Module.h"
29 #include "llvm/ParameterAttributes.h"
29 #include "llvm/Attributes.h"
3030 #include "llvm/Support/CFG.h"
3131 #include "llvm/Support/Compiler.h"
3232 #include "llvm/Pass.h"
1717 #include "llvm/Module.h"
1818 #include "llvm/Instructions.h"
1919 #include "llvm/Intrinsics.h"
20 #include "llvm/ParameterAttributes.h"
20 #include "llvm/Attributes.h"
2121 #include "llvm/Analysis/CallGraph.h"
2222 #include "llvm/Target/TargetData.h"
2323 #include "llvm/ADT/SmallVector.h"
10051005 void write(const Type *Ty) { printType(Ty); }
10061006
10071007 void writeOperand(const Value *Op, bool PrintType);
1008 void writeParamOperand(const Value *Operand, ParameterAttributes Attrs);
1008 void writeParamOperand(const Value *Operand, Attributes Attrs);
10091009
10101010 const Module* getModule() { return TheModule; }
10111011
10151015 void printGlobal(const GlobalVariable *GV);
10161016 void printAlias(const GlobalAlias *GV);
10171017 void printFunction(const Function *F);
1018 void printArgument(const Argument *FA, ParameterAttributes Attrs);
1018 void printArgument(const Argument *FA, Attributes Attrs);
10191019 void printBasicBlock(const BasicBlock *BB);
10201020 void printInstruction(const Instruction &I);
10211021
11251125 }
11261126
11271127 void AssemblyWriter::writeParamOperand(const Value *Operand,
1128 ParameterAttributes Attrs) {
1128 Attributes Attrs) {
11291129 if (Operand == 0) {
11301130 Out << "";
11311131 } else {
13851385 // Output type...
13861386 printType(FT->getParamType(i));
13871387
1388 ParameterAttributes ArgAttrs = Attrs.getParamAttrs(i+1);
1388 Attributes ArgAttrs = Attrs.getParamAttrs(i+1);
13891389 if (ArgAttrs != ParamAttr::None)
13901390 Out << ' ' << ParamAttr::getAsString(ArgAttrs);
13911391 }
13971397 Out << "..."; // Output varargs portion of signature!
13981398 }
13991399 Out << ')';
1400 ParameterAttributes RetAttrs = Attrs.getParamAttrs(0);
1400 Attributes RetAttrs = Attrs.getParamAttrs(0);
14011401 if (RetAttrs != ParamAttr::None)
14021402 Out << ' ' << ParamAttr::getAsString(Attrs.getParamAttrs(0));
14031403 if (F->hasSection())
14531453 /// the function. Simply print it out
14541454 ///
14551455 void AssemblyWriter::printArgument(const Argument *Arg,
1456 ParameterAttributes Attrs) {
1456 Attributes Attrs) {
14571457 // Output type...
14581458 printType(Arg->getType());
14591459
0 //===-- Attributes.cpp - Implement ParamAttrsList ----------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the ParamAttrsList class and ParamAttr utilities.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "llvm/Attributes.h"
14 #include "llvm/Type.h"
15 #include "llvm/ADT/StringExtras.h"
16 #include "llvm/ADT/FoldingSet.h"
17 #include "llvm/Support/Streams.h"
18 #include "llvm/Support/ManagedStatic.h"
19 using namespace llvm;
20
21 //===----------------------------------------------------------------------===//
22 // ParamAttr Function Definitions
23 //===----------------------------------------------------------------------===//
24
25 std::string ParamAttr::getAsString(Attributes Attrs) {
26 std::string Result;
27 if (Attrs & ParamAttr::ZExt)
28 Result += "zeroext ";
29 if (Attrs & ParamAttr::SExt)
30 Result += "signext ";
31 if (Attrs & ParamAttr::NoReturn)
32 Result += "noreturn ";
33 if (Attrs & ParamAttr::NoUnwind)
34 Result += "nounwind ";
35 if (Attrs & ParamAttr::InReg)
36 Result += "inreg ";
37 if (Attrs & ParamAttr::NoAlias)
38 Result += "noalias ";
39 if (Attrs & ParamAttr::StructRet)
40 Result += "sret ";
41 if (Attrs & ParamAttr::ByVal)
42 Result += "byval ";
43 if (Attrs & ParamAttr::Nest)
44 Result += "nest ";
45 if (Attrs & ParamAttr::ReadNone)
46 Result += "readnone ";
47 if (Attrs & ParamAttr::ReadOnly)
48 Result += "readonly ";
49 if (Attrs & ParamAttr::Alignment) {
50 Result += "align ";
51 Result += utostr((Attrs & ParamAttr::Alignment) >> 16);
52 Result += " ";
53 }
54 // Trim the trailing space.
55 Result.erase(Result.end()-1);
56 return Result;
57 }
58
59 Attributes ParamAttr::typeIncompatible(const Type *Ty) {
60 Attributes Incompatible = None;
61
62 if (!Ty->isInteger())
63 // Attributes that only apply to integers.
64 Incompatible |= SExt | ZExt;
65
66 if (!isa(Ty))
67 // Attributes that only apply to pointers.
68 Incompatible |= ByVal | Nest | NoAlias | StructRet;
69
70 return Incompatible;
71 }
72
73 //===----------------------------------------------------------------------===//
74 // ParamAttributeListImpl Definition
75 //===----------------------------------------------------------------------===//
76
77 namespace llvm {
78 class ParamAttributeListImpl : public FoldingSetNode {
79 unsigned RefCount;
80
81 // ParamAttrsList is uniqued, these should not be publicly available.
82 void operator=(const ParamAttributeListImpl &); // Do not implement
83 ParamAttributeListImpl(const ParamAttributeListImpl &); // Do not implement
84 ~ParamAttributeListImpl(); // Private implementation
85 public:
86 SmallVector Attrs;
87
88 ParamAttributeListImpl(const ParamAttrsWithIndex *Attr, unsigned NumAttrs)
89 : Attrs(Attr, Attr+NumAttrs) {
90 RefCount = 0;
91 }
92
93 void AddRef() { ++RefCount; }
94 void DropRef() { if (--RefCount == 0) delete this; }
95
96 void Profile(FoldingSetNodeID &ID) const {
97 Profile(ID, &Attrs[0], Attrs.size());
98 }
99 static void Profile(FoldingSetNodeID &ID, const ParamAttrsWithIndex *Attr,
100 unsigned NumAttrs) {
101 for (unsigned i = 0; i != NumAttrs; ++i)
102 ID.AddInteger(uint64_t(Attr[i].Attrs) << 32 | unsigned(Attr[i].Index));
103 }
104 };
105 }
106
107 static ManagedStatic > ParamAttrsLists;
108
109 ParamAttributeListImpl::~ParamAttributeListImpl() {
110 ParamAttrsLists->RemoveNode(this);
111 }
112
113
114 PAListPtr PAListPtr::get(const ParamAttrsWithIndex *Attrs, unsigned NumAttrs) {
115 // If there are no attributes then return a null ParamAttrsList pointer.
116 if (NumAttrs == 0)
117 return PAListPtr();
118
119 #ifndef NDEBUG
120 for (unsigned i = 0; i != NumAttrs; ++i) {
121 assert(Attrs[i].Attrs != ParamAttr::None &&
122 "Pointless parameter attribute!");
123 assert((!i || Attrs[i-1].Index < Attrs[i].Index) &&
124 "Misordered ParamAttrsList!");
125 }
126 #endif
127
128 // Otherwise, build a key to look up the existing attributes.
129 FoldingSetNodeID ID;
130 ParamAttributeListImpl::Profile(ID, Attrs, NumAttrs);
131 void *InsertPos;
132 ParamAttributeListImpl *PAL =
133 ParamAttrsLists->FindNodeOrInsertPos(ID, InsertPos);
134
135 // If we didn't find any existing attributes of the same shape then
136 // create a new one and insert it.
137 if (!PAL) {
138 PAL = new ParamAttributeListImpl(Attrs, NumAttrs);
139 ParamAttrsLists->InsertNode(PAL, InsertPos);
140 }
141
142 // Return the ParamAttrsList that we found or created.
143 return PAListPtr(PAL);
144 }
145
146
147 //===----------------------------------------------------------------------===//
148 // PAListPtr Method Implementations
149 //===----------------------------------------------------------------------===//
150
151 PAListPtr::PAListPtr(ParamAttributeListImpl *LI) : PAList(LI) {
152 if (LI) LI->AddRef();
153 }
154
155 PAListPtr::PAListPtr(const PAListPtr &P) : PAList(P.PAList) {
156 if (PAList) PAList->AddRef();
157 }
158
159 const PAListPtr &PAListPtr::operator=(const PAListPtr &RHS) {
160 if (PAList == RHS.PAList) return *this;
161 if (PAList) PAList->DropRef();
162 PAList = RHS.PAList;
163 if (PAList) PAList->AddRef();
164 return *this;
165 }
166
167 PAListPtr::~PAListPtr() {
168 if (PAList) PAList->DropRef();
169 }
170
171 /// getNumSlots - Return the number of slots used in this attribute list.
172 /// This is the number of arguments that have an attribute set on them
173 /// (including the function itself).
174 unsigned PAListPtr::getNumSlots() const {
175 return PAList ? PAList->Attrs.size() : 0;
176 }
177
178 /// getSlot - Return the ParamAttrsWithIndex at the specified slot. This
179 /// holds a parameter number plus a set of attributes.
180 const ParamAttrsWithIndex &PAListPtr::getSlot(unsigned Slot) const {
181 assert(PAList && Slot < PAList->Attrs.size() && "Slot # out of range!");
182 return PAList->Attrs[Slot];
183 }
184
185
186 /// getParamAttrs - The parameter attributes for the specified parameter are
187 /// returned. Parameters for the result are denoted with Idx = 0.
188 /// Function notes are denoted with idx = ~0.
189 Attributes PAListPtr::getParamAttrs(unsigned Idx) const {
190 if (PAList == 0) return ParamAttr::None;
191
192 const SmallVector &Attrs = PAList->Attrs;
193 for (unsigned i = 0, e = Attrs.size(); i != e && Attrs[i].Index <= Idx; ++i)
194 if (Attrs[i].Index == Idx)
195 return Attrs[i].Attrs;
196 return ParamAttr::None;
197 }
198
199 /// hasAttrSomewhere - Return true if the specified attribute is set for at
200 /// least one parameter or for the return value.
201 bool PAListPtr::hasAttrSomewhere(Attributes Attr) const {
202 if (PAList == 0) return false;
203
204 const SmallVector &Attrs = PAList->Attrs;
205 for (unsigned i = 0, e = Attrs.size(); i != e; ++i)
206 if (Attrs[i].Attrs & Attr)
207 return true;
208 return false;
209 }
210
211
212 PAListPtr PAListPtr::addAttr(unsigned Idx, Attributes Attrs) const {
213 Attributes OldAttrs = getParamAttrs(Idx);
214 #ifndef NDEBUG
215 // FIXME it is not obvious how this should work for alignment.
216 // For now, say we can't change a known alignment.
217 Attributes OldAlign = OldAttrs & ParamAttr::Alignment;
218 Attributes NewAlign = Attrs & ParamAttr::Alignment;
219 assert((!OldAlign || !NewAlign || OldAlign == NewAlign) &&
220 "Attempt to change alignment!");
221 #endif
222
223 Attributes NewAttrs = OldAttrs | Attrs;
224 if (NewAttrs == OldAttrs)
225 return *this;
226
227 SmallVector NewAttrList;
228 if (PAList == 0)
229 NewAttrList.push_back(ParamAttrsWithIndex::get(Idx, Attrs));
230 else {
231 const SmallVector &OldAttrList = PAList->Attrs;
232 unsigned i = 0, e = OldAttrList.size();
233 // Copy attributes for arguments before this one.
234 for (; i != e && OldAttrList[i].Index < Idx; ++i)
235 NewAttrList.push_back(OldAttrList[i]);
236
237 // If there are attributes already at this index, merge them in.
238 if (i != e && OldAttrList[i].Index == Idx) {
239 Attrs |= OldAttrList[i].Attrs;
240 ++i;
241 }
242
243 NewAttrList.push_back(ParamAttrsWithIndex::get(Idx, Attrs));
244
245 // Copy attributes for arguments after this one.
246 NewAttrList.insert(NewAttrList.end(),
247 OldAttrList.begin()+i, OldAttrList.end());
248 }
249
250 return get(&NewAttrList[0], NewAttrList.size());
251 }
252
253 PAListPtr PAListPtr::removeAttr(unsigned Idx, Attributes Attrs) const {
254 #ifndef NDEBUG
255 // FIXME it is not obvious how this should work for alignment.
256 // For now, say we can't pass in alignment, which no current use does.
257 assert(!(Attrs & ParamAttr::Alignment) && "Attempt to exclude alignment!");
258 #endif
259 if (PAList == 0) return PAListPtr();
260
261 Attributes OldAttrs = getParamAttrs(Idx);
262 Attributes NewAttrs = OldAttrs & ~Attrs;
263 if (NewAttrs == OldAttrs)
264 return *this;
265
266 SmallVector NewAttrList;
267 const SmallVector &OldAttrList = PAList->Attrs;
268 unsigned i = 0, e = OldAttrList.size();
269
270 // Copy attributes for arguments before this one.
271 for (; i != e && OldAttrList[i].Index < Idx; ++i)
272 NewAttrList.push_back(OldAttrList[i]);
273
274 // If there are attributes already at this index, merge them in.
275 assert(OldAttrList[i].Index == Idx && "Attribute isn't set?");
276 Attrs = OldAttrList[i].Attrs & ~Attrs;
277 ++i;
278 if (Attrs) // If any attributes left for this parameter, add them.
279 NewAttrList.push_back(ParamAttrsWithIndex::get(Idx, Attrs));
280
281 // Copy attributes for arguments after this one.
282 NewAttrList.insert(NewAttrList.end(),
283 OldAttrList.begin()+i, OldAttrList.end());
284
285 return get(&NewAttrList[0], NewAttrList.size());
286 }
287
288 void PAListPtr::dump() const {
289 cerr << "PAL[ ";
290 for (unsigned i = 0; i < getNumSlots(); ++i) {
291 const ParamAttrsWithIndex &PAWI = getSlot(i);
292 cerr << "{" << PAWI.Index << "," << PAWI.Attrs << "} ";
293 }
294
295 cerr << "]\n";
296 }
111111 }
112112
113113 /// addAttr - Add a ParamAttr to an argument
114 void Argument::addAttr(ParameterAttributes attr) {
114 void Argument::addAttr(Attributes attr) {
115115 getParent()->addParamAttr(getArgNo() + 1, attr);
116116 }
117117
118118 /// removeAttr - Remove a ParamAttr from an argument
119 void Argument::removeAttr(ParameterAttributes attr) {
119 void Argument::removeAttr(Attributes attr) {
120120 getParent()->removeParamAttr(getArgNo() + 1, attr);
121121 }
122122
228228 BasicBlocks.clear(); // Delete all basic blocks...
229229 }
230230
231 void Function::addParamAttr(unsigned i, ParameterAttributes attr) {
231 void Function::addParamAttr(unsigned i, Attributes attr) {
232232 PAListPtr PAL = getParamAttrs();
233233 PAL = PAL.addAttr(i, attr);
234234 setParamAttrs(PAL);
235235 }
236236
237 void Function::removeParamAttr(unsigned i, ParameterAttributes attr) {
237 void Function::removeParamAttr(unsigned i, Attributes attr) {
238238 PAListPtr PAL = getParamAttrs();
239239 PAL = PAL.removeAttr(i, attr);
240240 setParamAttrs(PAL);
355355 }
356356
357357 PAListPtr Intrinsic::getParamAttrs(ID id) {
358 ParameterAttributes Attr = ParamAttr::None;
358 Attributes Attr = ParamAttr::None;
359359
360360 #define GET_INTRINSIC_ATTRIBUTES
361361 #include "llvm/Intrinsics.gen"
5252 else
5353 cast(I)->setParamAttrs(PAL);
5454 }
55 bool CallSite::paramHasAttr(uint16_t i, ParameterAttributes attr) const {
55 bool CallSite::paramHasAttr(uint16_t i, Attributes attr) const {
5656 if (CallInst *CI = dyn_cast(I))
5757 return CI->paramHasAttr(i, attr);
5858 else
401401 OL[i] = InOL[i];
402402 }
403403
404 void CallInst::addParamAttr(unsigned i, ParameterAttributes attr) {
404 void CallInst::addParamAttr(unsigned i, Attributes attr) {
405405 PAListPtr PAL = getParamAttrs();
406406 PAL = PAL.addAttr(i, attr);
407407 setParamAttrs(PAL);
408408 }
409409
410 void CallInst::removeParamAttr(unsigned i, ParameterAttributes attr) {
410 void CallInst::removeParamAttr(unsigned i, Attributes attr) {
411411 PAListPtr PAL = getParamAttrs();
412412 PAL = PAL.removeAttr(i, attr);
413413 setParamAttrs(PAL);
414414 }
415415
416 bool CallInst::paramHasAttr(unsigned i, ParameterAttributes attr) const {
416 bool CallInst::paramHasAttr(unsigned i, Attributes attr) const {
417417 if (ParamAttrs.paramHasAttr(i, attr))
418418 return true;
419419 if (const Function *F = getCalledFunction())
472472 return setSuccessor(idx, B);
473473 }
474474
475 bool InvokeInst::paramHasAttr(unsigned i, ParameterAttributes attr) const {
475 bool InvokeInst::paramHasAttr(unsigned i, Attributes attr) const {
476476 if (ParamAttrs.paramHasAttr(i, attr))
477477 return true;
478478 if (const Function *F = getCalledFunction())
480480 return false;
481481 }
482482
483 void InvokeInst::addParamAttr(unsigned i, ParameterAttributes attr) {
483 void InvokeInst::addParamAttr(unsigned i, Attributes attr) {
484484 PAListPtr PAL = getParamAttrs();
485485 PAL = PAL.addAttr(i, attr);
486486 setParamAttrs(PAL);
487487 }
488488
489 void InvokeInst::removeParamAttr(unsigned i, ParameterAttributes attr) {
489 void InvokeInst::removeParamAttr(unsigned i, Attributes attr) {
490490 PAListPtr PAL = getParamAttrs();
491491 PAL = PAL.removeAttr(i, attr);
492492 setParamAttrs(PAL);
+0
-297
lib/VMCore/ParameterAttributes.cpp less more
None //===-- ParameterAttributes.cpp - Implement ParamAttrsList ----------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the ParamAttrsList class and ParamAttr utilities.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "llvm/ParameterAttributes.h"
14 #include "llvm/Type.h"
15 #include "llvm/ADT/StringExtras.h"
16 #include "llvm/ADT/FoldingSet.h"
17 #include "llvm/Support/Streams.h"
18 #include "llvm/Support/ManagedStatic.h"
19 using namespace llvm;
20
21 //===----------------------------------------------------------------------===//
22 // ParamAttr Function Definitions
23 //===----------------------------------------------------------------------===//
24
25 std::string ParamAttr::getAsString(ParameterAttributes Attrs) {
26 std::string Result;
27 if (Attrs & ParamAttr::ZExt)
28 Result += "zeroext ";
29 if (Attrs & ParamAttr::SExt)
30 Result += "signext ";
31 if (Attrs & ParamAttr::NoReturn)
32 Result += "noreturn ";
33 if (Attrs & ParamAttr::NoUnwind)
34 Result += "nounwind ";
35 if (Attrs & ParamAttr::InReg)
36 Result += "inreg ";
37 if (Attrs & ParamAttr::NoAlias)
38 Result += "noalias ";
39 if (Attrs & ParamAttr::StructRet)
40 Result += "sret ";
41 if (Attrs & ParamAttr::ByVal)
42 Result += "byval ";
43 if (Attrs & ParamAttr::Nest)
44 Result += "nest ";
45 if (Attrs & ParamAttr::ReadNone)
46 Result += "readnone ";
47 if (Attrs & ParamAttr::ReadOnly)
48 Result += "readonly ";
49 if (Attrs & ParamAttr::Alignment) {
50 Result += "align ";
51 Result += utostr((Attrs & ParamAttr::Alignment) >> 16);
52 Result += " ";
53 }
54 // Trim the trailing space.
55 Result.erase(Result.end()-1);
56 return Result;
57 }
58
59 ParameterAttributes ParamAttr::typeIncompatible(const Type *Ty) {
60 ParameterAttributes Incompatible = None;
61
62 if (!Ty->isInteger())
63 // Attributes that only apply to integers.
64 Incompatible |= SExt | ZExt;
65
66 if (!isa(Ty))
67 // Attributes that only apply to pointers.
68 Incompatible |= ByVal | Nest | NoAlias | StructRet;
69
70 return Incompatible;
71 }
72
73 //===----------------------------------------------------------------------===//
74 // ParamAttributeListImpl Definition
75 //===----------------------------------------------------------------------===//
76
77 namespace llvm {
78 class ParamAttributeListImpl : public FoldingSetNode {
79 unsigned RefCount;
80
81 // ParamAttrsList is uniqued, these should not be publicly available.
82 void operator=(const ParamAttributeListImpl &); // Do not implement
83 ParamAttributeListImpl(const ParamAttributeListImpl &); // Do not implement
84 ~ParamAttributeListImpl(); // Private implementation
85 public:
86 SmallVector Attrs;
87
88 ParamAttributeListImpl(const ParamAttrsWithIndex *Attr, unsigned NumAttrs)
89 : Attrs(Attr, Attr+NumAttrs) {
90 RefCount = 0;
91 }
92
93 void AddRef() { ++RefCount; }
94 void DropRef() { if (--RefCount == 0) delete this; }
95
96 void Profile(FoldingSetNodeID &ID) const {
97 Profile(ID, &Attrs[0], Attrs.size());
98 }
99 static void Profile(FoldingSetNodeID &ID, const ParamAttrsWithIndex *Attr,
100 unsigned NumAttrs) {
101 for (unsigned i = 0; i != NumAttrs; ++i)
102 ID.AddInteger(uint64_t(Attr[i].Attrs) << 32 | unsigned(Attr[i].Index));
103 }
104 };
105 }
106
107 static ManagedStatic > ParamAttrsLists;
108
109 ParamAttributeListImpl::~ParamAttributeListImpl() {
110 ParamAttrsLists->RemoveNode(this);
111 }
112
113
114 PAListPtr PAListPtr::get(const ParamAttrsWithIndex *Attrs, unsigned NumAttrs) {
115 // If there are no attributes then return a null ParamAttrsList pointer.
116 if (NumAttrs == 0)
117 return PAListPtr();
118
119 #ifndef NDEBUG
120 for (unsigned i = 0; i != NumAttrs; ++i) {
121 assert(Attrs[i].Attrs != ParamAttr::None &&
122 "Pointless parameter attribute!");
123 assert((!i || Attrs[i-1].Index < Attrs[i].Index) &&
124 "Misordered ParamAttrsList!");
125 }
126 #endif
127
128 // Otherwise, build a key to look up the existing attributes.
129 FoldingSetNodeID ID;
130 ParamAttributeListImpl::Profile(ID, Attrs, NumAttrs);
131 void *InsertPos;
132 ParamAttributeListImpl *PAL =
133 ParamAttrsLists->FindNodeOrInsertPos(ID, InsertPos);
134
135 // If we didn't find any existing attributes of the same shape then
136 // create a new one and insert it.
137 if (!PAL) {
138 PAL = new ParamAttributeListImpl(Attrs, NumAttrs);
139 ParamAttrsLists->InsertNode(PAL, InsertPos);
140 }
141
142 // Return the ParamAttrsList that we found or created.
143 return PAListPtr(PAL);
144 }
145
146
147 //===----------------------------------------------------------------------===//
148 // PAListPtr Method Implementations
149 //===----------------------------------------------------------------------===//
150
151 PAListPtr::PAListPtr(ParamAttributeListImpl *LI) : PAList(LI) {
152 if (LI) LI->AddRef();
153 }
154
155 PAListPtr::PAListPtr(const PAListPtr &P) : PAList(P.PAList) {
156 if (PAList) PAList->AddRef();
157 }
158
159 const PAListPtr &PAListPtr::operator=(const PAListPtr &RHS) {
160 if (PAList == RHS.PAList) return *this;
161 if (PAList) PAList->DropRef();
162 PAList = RHS.PAList;
163 if (PAList) PAList->AddRef();
164 return *this;
165 }
166
167 PAListPtr::~PAListPtr() {
168 if (PAList) PAList->DropRef();
169 }
170
171 /// getNumSlots - Return the number of slots used in this attribute list.
172 /// This is the number of arguments that have an attribute set on them
173 /// (including the function itself).
174 unsigned PAListPtr::getNumSlots() const {
175 return PAList ? PAList->Attrs.size() : 0;
176 }
177
178 /// getSlot - Return the ParamAttrsWithIndex at the specified slot. This
179 /// holds a parameter number plus a set of attributes.
180 const ParamAttrsWithIndex &PAListPtr::getSlot(unsigned Slot) const {
181 assert(PAList && Slot < PAList->Attrs.size() && "Slot # out of range!");
182 return PAList->Attrs[Slot];
183 }
184
185
186 /// getParamAttrs - The parameter attributes for the specified parameter are
187 /// returned. Parameters for the result are denoted with Idx = 0.
188 /// Function notes are denoted with idx = ~0.
189 ParameterAttributes PAListPtr::getParamAttrs(unsigned Idx) const {
190 if (PAList == 0) return ParamAttr::None;
191
192 const SmallVector &Attrs = PAList->Attrs;
193 for (unsigned i = 0, e = Attrs.size(); i != e && Attrs[i].Index <= Idx; ++i)
194 if (Attrs[i].Index == Idx)
195 return Attrs[i].Attrs;
196 return ParamAttr::None;
197 }
198
199 /// hasAttrSomewhere - Return true if the specified attribute is set for at
200 /// least one parameter or for the return value.
201 bool PAListPtr::hasAttrSomewhere(ParameterAttributes Attr) const {
202 if (PAList == 0) return false;
203
204 const SmallVector &Attrs = PAList->Attrs;
205 for (unsigned i = 0, e = Attrs.size(); i != e; ++i)
206 if (Attrs[i].Attrs & Attr)
207 return true;
208 return false;
209 }
210
211
212 PAListPtr PAListPtr::addAttr(unsigned Idx, ParameterAttributes Attrs) const {
213 ParameterAttributes OldAttrs = getParamAttrs(Idx);
214 #ifndef NDEBUG
215 // FIXME it is not obvious how this should work for alignment.
216 // For now, say we can't change a known alignment.
217 ParameterAttributes OldAlign = OldAttrs & ParamAttr::Alignment;
218 ParameterAttributes NewAlign = Attrs & ParamAttr::Alignment;
219 assert((!OldAlign || !NewAlign || OldAlign == NewAlign) &&
220 "Attempt to change alignment!");
221 #endif
222
223 ParameterAttributes NewAttrs = OldAttrs | Attrs;
224 if (NewAttrs == OldAttrs)
225 return *this;
226
227 SmallVector NewAttrList;
228 if (PAList == 0)
229 NewAttrList.push_back(ParamAttrsWithIndex::get(Idx, Attrs));
230 else {
231 const SmallVector &OldAttrList = PAList->Attrs;
232 unsigned i = 0, e = OldAttrList.size();
233 // Copy attributes for arguments before this one.
234 for (; i != e && OldAttrList[i].Index < Idx; ++i)
235 NewAttrList.push_back(OldAttrList[i]);
236
237 // If there are attributes already at this index, merge them in.
238 if (i != e && OldAttrList[i].Index == Idx) {
239 Attrs |= OldAttrList[i].Attrs;
240 ++i;
241 }
242
243 NewAttrList.push_back(ParamAttrsWithIndex::get(Idx, Attrs));
244
245 // Copy attributes for arguments after this one.
246 NewAttrList.insert(NewAttrList.end(),
247 OldAttrList.begin()+i, OldAttrList.end());
248 }
249
250 return get(&NewAttrList[0], NewAttrList.size());
251 }
252
253 PAListPtr PAListPtr::removeAttr(unsigned Idx, ParameterAttributes Attrs) const {
254 #ifndef NDEBUG
255 // FIXME it is not obvious how this should work for alignment.
256 // For now, say we can't pass in alignment, which no current use does.
257 assert(!(Attrs & ParamAttr::Alignment) && "Attempt to exclude alignment!");
258 #endif
259 if (PAList == 0) return PAListPtr();
260
261 ParameterAttributes OldAttrs = getParamAttrs(Idx);
262 ParameterAttributes NewAttrs = OldAttrs & ~Attrs;
263 if (NewAttrs == OldAttrs)
264 return *this;
265
266 SmallVector NewAttrList;
267 const SmallVector &OldAttrList = PAList->Attrs;
268 unsigned i = 0, e = OldAttrList.size();
269
270 // Copy attributes for arguments before this one.
271 for (; i != e && OldAttrList[i].Index < Idx; ++i)
272 NewAttrList.push_back(OldAttrList[i]);
273
274 // If there are attributes already at this index, merge them in.
275 assert(OldAttrList[i].Index == Idx && "Attribute isn't set?");
276 Attrs = OldAttrList[i].Attrs & ~Attrs;
277 ++i;
278 if (Attrs) // If any attributes left for this parameter, add them.
279 NewAttrList.push_back(ParamAttrsWithIndex::get(Idx, Attrs));
280
281 // Copy attributes for arguments after this one.
282 NewAttrList.insert(NewAttrList.end(),
283 OldAttrList.begin()+i, OldAttrList.end());
284
285 return get(&NewAttrList[0], NewAttrList.size());
286 }
287
288 void PAListPtr::dump() const {
289 cerr << "PAL[ ";
290 for (unsigned i = 0; i < getNumSlots(); ++i) {
291 const ParamAttrsWithIndex &PAWI = getSlot(i);
292 cerr << "{" << PAWI.Index << "," << PAWI.Attrs << "} ";
293 }
294
295 cerr << "]\n";
296 }
267267 void VerifyCallSite(CallSite CS);
268268 void VerifyIntrinsicPrototype(Intrinsic::ID ID, Function *F,
269269 unsigned Count, ...);
270 void VerifyAttrs(ParameterAttributes Attrs, const Type *Ty,
270 void VerifyAttrs(Attributes Attrs, const Type *Ty,
271271 bool isReturnValue, const Value *V);
272272 void VerifyFunctionAttrs(const FunctionType *FT, const PAListPtr &Attrs,
273273 const Value *V);
405405
406406 // VerifyAttrs - Check the given parameter attributes for an argument or return
407407 // value of the specified type. The value V is printed in error messages.
408 void Verifier::VerifyAttrs(ParameterAttributes Attrs, const Type *Ty,
408 void Verifier::VerifyAttrs(Attributes Attrs, const Type *Ty,
409409 bool isReturnValue, const Value *V) {
410410 if (Attrs == ParamAttr::None)
411411 return;
412412
413413 if (isReturnValue) {
414 ParameterAttributes RetI = Attrs & ParamAttr::ParameterOnly;
414 Attributes RetI = Attrs & ParamAttr::ParameterOnly;
415415 Assert1(!RetI, "Attribute " + ParamAttr::getAsString(RetI) +
416416 " does not apply to return values!", V);
417417 } else {
418 ParameterAttributes ParmI = Attrs & ParamAttr::ReturnOnly;
418 Attributes ParmI = Attrs & ParamAttr::ReturnOnly;
419419 Assert1(!ParmI, "Attribute " + ParamAttr::getAsString(ParmI) +
420420 " only applies to return values!", V);
421421 }
422422
423423 for (unsigned i = 0;
424424 i < array_lengthof(ParamAttr::MutuallyIncompatible); ++i) {
425 ParameterAttributes MutI = Attrs & ParamAttr::MutuallyIncompatible[i];
425 Attributes MutI = Attrs & ParamAttr::MutuallyIncompatible[i];
426426 Assert1(!(MutI & (MutI - 1)), "Attributes " +
427427 ParamAttr::getAsString(MutI) + " are incompatible!", V);
428428 }
429429
430 ParameterAttributes TypeI = Attrs & ParamAttr::typeIncompatible(Ty);
430 Attributes TypeI = Attrs & ParamAttr::typeIncompatible(Ty);
431431 Assert1(!TypeI, "Wrong type for attribute " +
432432 ParamAttr::getAsString(TypeI), V);
433433
434 ParameterAttributes ByValI = Attrs & ParamAttr::ByVal;
434 Attributes ByValI = Attrs & ParamAttr::ByVal;
435435 if (const PointerType *PTy = dyn_cast(Ty)) {
436436 Assert1(!ByValI || PTy->getElementType()->isSized(),
437437 "Attribute " + ParamAttr::getAsString(ByValI) +
975975 if (FTy->isVarArg())
976976 // Check attributes on the varargs part.
977977 for (unsigned Idx = 1 + FTy->getNumParams(); Idx <= CS.arg_size(); ++Idx) {
978 ParameterAttributes Attr = Attrs.getParamAttrs(Idx);
978 Attributes Attr = Attrs.getParamAttrs(Idx);
979979
980980 VerifyAttrs(Attr, CS.getArgument(Idx-1)->getType(), false, I);
981981
982 ParameterAttributes VArgI = Attr & ParamAttr::VarArgsIncompatible;
982 Attributes VArgI = Attr & ParamAttr::VarArgsIncompatible;
983983 Assert1(!VArgI, "Attribute " + ParamAttr::getAsString(VArgI) +
984984 " cannot be used for vararg call arguments!", I);
985985 }