llvm.org GIT mirror llvm / 757d243
Add a convenience method for modifying parameter attributes. While there, I noticed that not all attribute methods returned a pointer-to-constant, so I fixed that. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44457 91177308-0d34-0410-b5e6-96231b3b80d8 Duncan Sands 11 years ago
4 changed file(s) with 79 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
129129 : attrs(attrVec), refCount(0) {}
130130
131131 public:
132 /// This method ensures the uniqueness of ParamAttrsList instances. The
132 /// This method ensures the uniqueness of ParamAttrsList instances. The
133133 /// argument is a vector of attribute/index pairs as represented by the
134 /// ParamAttrsWithIndex structure. The vector is used in the construction of
135 /// the ParamAttrsList instance. If an instance with identical vector pairs
136 /// exists, it will be returned instead of creating a new instance.
134 /// ParamAttrsWithIndex structure. The index values must be in strictly
135 /// increasing order and ParamAttr::None is not allowed. The vector is
136 /// used to construct the ParamAttrsList instance. If an instance with
137 /// identical vector pairs exists, it will be returned instead of creating
138 /// a new instance.
137139 /// @brief Get a ParamAttrsList instance.
138 static ParamAttrsList *get(const ParamAttrsVector &attrVec);
140 static const ParamAttrsList *get(const ParamAttrsVector &attrVec);
141
142 /// Returns the ParamAttrsList obtained by modifying PAL using the supplied
143 /// list of attribute/index pairs. Any existing attributes for the given
144 /// index are replaced by the given attributes. If there were no attributes
145 /// then the new ones are inserted. Attributes can be deleted by replacing
146 /// them with ParamAttr::None. Index values must be strictly increasing.
147 /// @brief Get a new ParamAttrsList instance by modifying an existing one.
148 static const ParamAttrsList *getModified(const ParamAttrsList *PAL,
149 const ParamAttrsVector &modVec);
139150
140151 /// Returns whether each of the specified lists of attributes can be safely
141152 /// replaced with the other in a function or a function call.
22422242 bool isVarArg = ParamTypeList.size() && ParamTypeList.back() == Type::VoidTy;
22432243 if (isVarArg) ParamTypeList.pop_back();
22442244
2245 ParamAttrsList *PAL = 0;
2245 const ParamAttrsList *PAL = 0;
22462246 if (!Attrs.empty())
22472247 PAL = ParamAttrsList::get(Attrs);
22482248
26442644 GEN_ERROR("Invalid number of parameters detected");
26452645 }
26462646
2647 ParamAttrsList *PAL = 0;
2647 const ParamAttrsList *PAL = 0;
26482648 if (!Attrs.empty())
26492649 PAL = ParamAttrsList::get(Attrs);
26502650
29762976 }
29772977
29782978 // Finish off the ParamAttrs and check them
2979 ParamAttrsList *PAL = 0;
2979 const ParamAttrsList *PAL = 0;
29802980 if (!Attrs.empty())
29812981 PAL = ParamAttrsList::get(Attrs);
29822982
166166
167167 static ManagedStatic > ParamAttrsLists;
168168
169 ParamAttrsList *
169 const ParamAttrsList *
170170 ParamAttrsList::get(const ParamAttrsVector &attrVec) {
171171 // If there are no attributes then return a null ParamAttrsList pointer.
172172 if (attrVec.empty())
197197
198198 // Return the ParamAttrsList that we found or created.
199199 return PAL;
200 }
201
202 const ParamAttrsList *
203 ParamAttrsList::getModified(const ParamAttrsList *PAL,
204 const ParamAttrsVector &modVec) {
205 if (modVec.empty())
206 return PAL;
207
208 #ifndef NDEBUG
209 for (unsigned i = 0, e = modVec.size(); i < e; ++i)
210 assert((!i || modVec[i-1].index < modVec[i].index)
211 && "Misordered ParamAttrsList!");
212 #endif
213
214 if (!PAL) {
215 // Strip any instances of ParamAttr::None from modVec before calling 'get'.
216 ParamAttrsVector newVec;
217 for (unsigned i = 0, e = modVec.size(); i < e; ++i)
218 if (modVec[i].attrs != ParamAttr::None)
219 newVec.push_back(modVec[i]);
220 return get(newVec);
221 }
222
223 const ParamAttrsVector &oldVec = PAL->attrs;
224
225 ParamAttrsVector newVec;
226 unsigned oldI = 0;
227 unsigned modI = 0;
228 unsigned oldE = oldVec.size();
229 unsigned modE = modVec.size();
230
231 while (oldI < oldE && modI < modE) {
232 uint16_t oldIndex = oldVec[oldI].index;
233 uint16_t modIndex = modVec[modI].index;
234
235 if (oldIndex < modIndex) {
236 newVec.push_back(oldVec[oldI]);
237 ++oldI;
238 } else if (modIndex < oldIndex) {
239 if (modVec[modI].attrs != ParamAttr::None)
240 newVec.push_back(modVec[modI]);
241 ++modI;
242 } else {
243 // Same index - overwrite or delete existing attributes.
244 if (modVec[modI].attrs != ParamAttr::None)
245 newVec.push_back(modVec[modI]);
246 ++oldI;
247 ++modI;
248 }
249 }
250
251 for (; oldI < oldE; ++oldI)
252 newVec.push_back(oldVec[oldI]);
253 for (; modI < modE; ++modI)
254 if (modVec[modI].attrs != ParamAttr::None)
255 newVec.push_back(modVec[modI]);
256
257 return get(newVec);
200258 }
201259
202260 ParamAttrsList::~ParamAttrsList() {
20542054 bool isVarArg = Params.size() && Params.back() == Type::VoidTy;
20552055 if (isVarArg) Params.pop_back();
20562056
2057 ParamAttrsList *PAL = 0;
2057 const ParamAttrsList *PAL = 0;
20582058 if (lastCallingConv == OldCallingConv::CSRet) {
20592059 ParamAttrsVector Attrs;
20602060 ParamAttrsWithIndex PAWI;