llvm.org GIT mirror llvm / 6707770
Rename AttributeSet to AttributeList Summary: This class is a list of AttributeSetNodes corresponding the function prototype of a call or function declaration. This class used to be called ParamAttrListPtr, then AttrListPtr, then AttributeSet. It is typically accessed by parameter and return value index, so "AttributeList" seems like a more intuitive name. Rename AttributeSetImpl to AttributeListImpl to follow suit. It's useful to rename this class so that we can rename AttributeSetNode to AttributeSet later. AttributeSet is the set of attributes that apply to a single function, argument, or return value. Reviewers: sanjoy, javed.absar, chandlerc, pete Reviewed By: pete Subscribers: pete, jholewinski, arsenm, dschuff, mehdi_amini, jfb, nhaehnle, sbc100, void, llvm-commits Differential Revision: https://reviews.llvm.org/D31102 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@298393 91177308-0d34-0410-b5e6-96231b3b80d8 Reid Kleckner 2 years ago
94 changed file(s) with 983 addition(s) and 982 deletion(s). Raw diff Collapse all Expand all
3737 convert any code which does treat them as a bit mask to use the new query
3838 methods on the Attribute class.
3939
40 ``AttributeSet``
40 ``AttributeList``
4141 ================
4242
43 The ``AttributeSet`` class replaces the old ``AttributeList`` class. The
44 ``AttributeSet`` stores a collection of Attribute objects for each kind of
45 object that may have an attribute associated with it: the function as a
46 whole, the return type, or the function's parameters. A function's attributes
47 are at index ``AttributeSet::FunctionIndex``; the return type's attributes are
48 at index ``AttributeSet::ReturnIndex``; and the function's parameters'
49 attributes are at indices 1, ..., n (where 'n' is the number of parameters).
50 Most methods on the ``AttributeSet`` class take an index parameter.
43 The ``AttributeList`` stores a collection of Attribute objects for each kind of
44 object that may have an attribute associated with it: the function as a whole,
45 the return type, or the function's parameters. A function's attributes are at
46 index ``AttributeList::FunctionIndex``; the return type's attributes are at
47 index ``AttributeList::ReturnIndex``; and the function's parameters' attributes
48 are at indices 1, ..., n (where 'n' is the number of parameters). Most methods
49 on the ``AttributeList`` class take an index parameter.
5150
52 An ``AttributeSet`` is also a uniqued and immutable object. You create an
53 ``AttributeSet`` through the ``AttributeSet::get`` methods. You can add and
54 remove attributes, which result in the creation of a new ``AttributeSet``.
51 An ``AttributeList`` is also a uniqued and immutable object. You create an
52 ``AttributeList`` through the ``AttributeList::get`` methods. You can add and
53 remove attributes, which result in the creation of a new ``AttributeList``.
5554
56 An ``AttributeSet`` object is designed to be passed around by value.
55 An ``AttributeList`` object is designed to be passed around by value.
5756
58 Note: It is advised that you do *not* use the ``AttributeSet`` "introspection"
57 Note: It is advised that you do *not* use the ``AttributeList`` "introspection"
5958 methods (e.g. ``Raw``, ``getRawPointer``, etc.). These methods break
6059 encapsulation, and may be removed in a future release (i.e. LLVM 4.0).
6160
6261 ``AttrBuilder``
6362 ===============
6463
65 Lastly, we have a "builder" class to help create the ``AttributeSet`` object
64 Lastly, we have a "builder" class to help create the ``AttributeList`` object
6665 without having to create several different intermediate uniqued
67 ``AttributeSet`` objects. The ``AttrBuilder`` class allows you to add and
66 ``AttributeList`` objects. The ``AttrBuilder`` class allows you to add and
6867 remove attributes at will. The attributes won't be uniqued until you call the
69 appropriate ``AttributeSet::get`` method.
68 appropriate ``AttributeList::get`` method.
7069
7170 An ``AttrBuilder`` object is *not* designed to be passed around by value. It
7271 should be passed by reference.
345345 Module &M) {
346346 for (auto &F : M) {
347347 auto &Ctx = F.getContext();
348 AttributeSet Attrs = F.getAttributes(), NewAttrs;
348 AttributeList Attrs = F.getAttributes(), NewAttrs;
349349
350350 if (!CPU.empty())
351 NewAttrs = NewAttrs.addAttribute(Ctx, AttributeSet::FunctionIndex,
351 NewAttrs = NewAttrs.addAttribute(Ctx, AttributeList::FunctionIndex,
352352 "target-cpu", CPU);
353353
354354 if (!Features.empty())
355 NewAttrs = NewAttrs.addAttribute(Ctx, AttributeSet::FunctionIndex,
355 NewAttrs = NewAttrs.addAttribute(Ctx, AttributeList::FunctionIndex,
356356 "target-features", Features);
357357
358358 if (DisableFPElim.getNumOccurrences() > 0)
359 NewAttrs = NewAttrs.addAttribute(Ctx, AttributeSet::FunctionIndex,
359 NewAttrs = NewAttrs.addAttribute(Ctx, AttributeList::FunctionIndex,
360360 "no-frame-pointer-elim",
361361 DisableFPElim ? "true" : "false");
362362
363363 if (DisableTailCalls.getNumOccurrences() > 0)
364 NewAttrs = NewAttrs.addAttribute(Ctx, AttributeSet::FunctionIndex,
364 NewAttrs = NewAttrs.addAttribute(Ctx, AttributeList::FunctionIndex,
365365 "disable-tail-calls",
366366 toStringRef(DisableTailCalls));
367367
368368 if (StackRealign)
369 NewAttrs = NewAttrs.addAttribute(Ctx, AttributeSet::FunctionIndex,
369 NewAttrs = NewAttrs.addAttribute(Ctx, AttributeList::FunctionIndex,
370370 "stackrealign");
371371
372372 if (TrapFuncName.getNumOccurrences() > 0)
376376 if (const auto *F = Call->getCalledFunction())
377377 if (F->getIntrinsicID() == Intrinsic::debugtrap ||
378378 F->getIntrinsicID() == Intrinsic::trap)
379 Call->addAttribute(llvm::AttributeSet::FunctionIndex,
380 Attribute::get(Ctx, "trap-func-name",
381 TrapFuncName));
379 Call->addAttribute(
380 llvm::AttributeList::FunctionIndex,
381 Attribute::get(Ctx, "trap-func-name", TrapFuncName));
382382
383383 // Let NewAttrs override Attrs.
384 NewAttrs = Attrs.addAttributes(Ctx, AttributeSet::FunctionIndex, NewAttrs);
384 NewAttrs = Attrs.addAttributes(Ctx, AttributeList::FunctionIndex, NewAttrs);
385385 F.setAttributes(NewAttrs);
386386 }
387387 }
107107 bool hasSExtAttr() const;
108108
109109 /// Add attributes to an argument.
110 void addAttr(AttributeSet AS);
110 void addAttr(AttributeList AS);
111111
112112 void addAttr(Attribute::AttrKind Kind) {
113 addAttr(AttributeSet::get(getContext(), getArgNo() + 1, Kind));
113 addAttr(AttributeList::get(getContext(), getArgNo() + 1, Kind));
114114 }
115115
116116 /// Remove attributes from an argument.
117 void removeAttr(AttributeSet AS);
117 void removeAttr(AttributeList AS);
118118
119119 void removeAttr(Attribute::AttrKind Kind) {
120 removeAttr(AttributeSet::get(getContext(), getArgNo() + 1, Kind));
120 removeAttr(AttributeList::get(getContext(), getArgNo() + 1, Kind));
121121 }
122122
123123 /// Check if an argument has a given attribute.
3333
3434 class AttrBuilder;
3535 class AttributeImpl;
36 class AttributeSetImpl;
36 class AttributeListImpl;
3737 class AttributeSetNode;
3838 template struct DenseMapInfo;
3939 class Function;
198198 /// \class
199199 /// \brief This class holds the attributes for a function, its return value, and
200200 /// its parameters. You access the attributes for each of them via an index into
201 /// the AttributeSet object. The function attributes are at index
202 /// `AttributeSet::FunctionIndex', the return value is at index
203 /// `AttributeSet::ReturnIndex', and the attributes for the parameters start at
201 /// the AttributeList object. The function attributes are at index
202 /// `AttributeList::FunctionIndex', the return value is at index
203 /// `AttributeList::ReturnIndex', and the attributes for the parameters start at
204204 /// index `1'.
205 class AttributeSet {
205 class AttributeList {
206206 public:
207207 enum AttrIndex : unsigned {
208208 ReturnIndex = 0U,
211211
212212 private:
213213 friend class AttrBuilder;
214 friend class AttributeSetImpl;
214 friend class AttributeListImpl;
215215 friend class AttributeSetNode;
216216
217217 template friend struct DenseMapInfo;
218218
219219 /// \brief The attributes that we are managing. This can be null to represent
220220 /// the empty attributes list.
221 AttributeSetImpl *pImpl = nullptr;
221 AttributeListImpl *pImpl = nullptr;
222222
223223 /// \brief The attributes for the specified index are returned.
224224 AttributeSetNode *getAttributes(unsigned Index) const;
225225
226 /// \brief Create an AttributeSet with the specified parameters in it.
227 static AttributeSet get(LLVMContext &C,
228 ArrayRef> Attrs);
229 static AttributeSet get(LLVMContext &C,
230 ArrayRef
231 AttributeSetNode*>> Attrs);
232
233 static AttributeSet getImpl(LLVMContext &C,
234 ArrayRef
235 AttributeSetNode*>> Attrs);
236
237 explicit AttributeSet(AttributeSetImpl *LI) : pImpl(LI) {}
226 /// \brief Create an AttributeList with the specified parameters in it.
227 static AttributeList get(LLVMContext &C,
228 ArrayRef> Attrs);
229 static AttributeList
230 get(LLVMContext &C, ArrayRef> Attrs);
231
232 static AttributeList
233 getImpl(LLVMContext &C,
234 ArrayRef> Attrs);
235
236 explicit AttributeList(AttributeListImpl *LI) : pImpl(LI) {}
238237
239238 public:
240 AttributeSet() = default;
241
242 //===--------------------------------------------------------------------===//
243 // AttributeSet Construction and Mutation
244 //===--------------------------------------------------------------------===//
245
246 /// \brief Return an AttributeSet with the specified parameters in it.
247 static AttributeSet get(LLVMContext &C, ArrayRef Attrs);
248 static AttributeSet get(LLVMContext &C, unsigned Index,
249 ArrayRef Kinds);
250 static AttributeSet get(LLVMContext &C, unsigned Index,
251 ArrayRef Kind);
252 static AttributeSet get(LLVMContext &C, unsigned Index, const AttrBuilder &B);
239 AttributeList() = default;
240
241 //===--------------------------------------------------------------------===//
242 // AttributeList Construction and Mutation
243 //===--------------------------------------------------------------------===//
244
245 /// \brief Return an AttributeList with the specified parameters in it.
246 static AttributeList get(LLVMContext &C, ArrayRef Attrs);
247 static AttributeList get(LLVMContext &C, unsigned Index,
248 ArrayRef Kinds);
249 static AttributeList get(LLVMContext &C, unsigned Index,
250 ArrayRef Kind);
251 static AttributeList get(LLVMContext &C, unsigned Index,
252 const AttrBuilder &B);
253253
254254 /// \brief Add an attribute to the attribute set at the given index. Because
255255 /// attribute sets are immutable, this returns a new set.
256 AttributeSet addAttribute(LLVMContext &C, unsigned Index,
257 Attribute::AttrKind Kind) const;
256 AttributeList addAttribute(LLVMContext &C, unsigned Index,
257 Attribute::AttrKind Kind) const;
258258
259259 /// \brief Add an attribute to the attribute set at the given index. Because
260260 /// attribute sets are immutable, this returns a new set.
261 AttributeSet addAttribute(LLVMContext &C, unsigned Index, StringRef Kind,
262 StringRef Value = StringRef()) const;
261 AttributeList addAttribute(LLVMContext &C, unsigned Index, StringRef Kind,
262 StringRef Value = StringRef()) const;
263263
264264 /// Add an attribute to the attribute set at the given indices. Because
265265 /// attribute sets are immutable, this returns a new set.
266 AttributeSet addAttribute(LLVMContext &C, ArrayRef Indices,
267 Attribute A) const;
266 AttributeList addAttribute(LLVMContext &C, ArrayRef Indices,
267 Attribute A) const;
268268
269269 /// \brief Add attributes to the attribute set at the given index. Because
270270 /// attribute sets are immutable, this returns a new set.
271 AttributeSet addAttributes(LLVMContext &C, unsigned Index,
272 AttributeSet Attrs) const;
271 AttributeList addAttributes(LLVMContext &C, unsigned Index,
272 AttributeList Attrs) const;
273273
274274 /// \brief Remove the specified attribute at the specified index from this
275275 /// attribute list. Because attribute lists are immutable, this returns the
276276 /// new list.
277 AttributeSet removeAttribute(LLVMContext &C, unsigned Index,
278 Attribute::AttrKind Kind) const;
277 AttributeList removeAttribute(LLVMContext &C, unsigned Index,
278 Attribute::AttrKind Kind) const;
279279
280280 /// \brief Remove the specified attribute at the specified index from this
281281 /// attribute list. Because attribute lists are immutable, this returns the
282282 /// new list.
283 AttributeSet removeAttribute(LLVMContext &C, unsigned Index,
284 StringRef Kind) const;
283 AttributeList removeAttribute(LLVMContext &C, unsigned Index,
284 StringRef Kind) const;
285285
286286 /// \brief Remove the specified attributes at the specified index from this
287287 /// attribute list. Because attribute lists are immutable, this returns the
288288 /// new list.
289 AttributeSet removeAttributes(LLVMContext &C, unsigned Index,
290 AttributeSet Attrs) const;
289 AttributeList removeAttributes(LLVMContext &C, unsigned Index,
290 AttributeList Attrs) const;
291291
292292 /// \brief Remove the specified attributes at the specified index from this
293293 /// attribute list. Because attribute lists are immutable, this returns the
294294 /// new list.
295 AttributeSet removeAttributes(LLVMContext &C, unsigned Index,
296 const AttrBuilder &Attrs) const;
295 AttributeList removeAttributes(LLVMContext &C, unsigned Index,
296 const AttrBuilder &Attrs) const;
297297
298298 /// \brief Add the dereferenceable attribute to the attribute set at the given
299299 /// index. Because attribute sets are immutable, this returns a new set.
300 AttributeSet addDereferenceableAttr(LLVMContext &C, unsigned Index,
301 uint64_t Bytes) const;
300 AttributeList addDereferenceableAttr(LLVMContext &C, unsigned Index,
301 uint64_t Bytes) const;
302302
303303 /// \brief Add the dereferenceable_or_null attribute to the attribute set at
304304 /// the given index. Because attribute sets are immutable, this returns a new
305305 /// set.
306 AttributeSet addDereferenceableOrNullAttr(LLVMContext &C, unsigned Index,
307 uint64_t Bytes) const;
306 AttributeList addDereferenceableOrNullAttr(LLVMContext &C, unsigned Index,
307 uint64_t Bytes) const;
308308
309309 /// Add the allocsize attribute to the attribute set at the given index.
310310 /// Because attribute sets are immutable, this returns a new set.
311 AttributeSet addAllocSizeAttr(LLVMContext &C, unsigned Index,
312 unsigned ElemSizeArg,
313 const Optional &NumElemsArg);
314
315 //===--------------------------------------------------------------------===//
316 // AttributeSet Accessors
311 AttributeList addAllocSizeAttr(LLVMContext &C, unsigned Index,
312 unsigned ElemSizeArg,
313 const Optional &NumElemsArg);
314
315 //===--------------------------------------------------------------------===//
316 // AttributeList Accessors
317317 //===--------------------------------------------------------------------===//
318318
319319 /// \brief Retrieve the LLVM context.
320320 LLVMContext &getContext() const;
321321
322322 /// \brief The attributes for the specified index are returned.
323 AttributeSet getParamAttributes(unsigned Index) const;
323 AttributeList getParamAttributes(unsigned Index) const;
324324
325325 /// \brief The attributes for the ret value are returned.
326 AttributeSet getRetAttributes() const;
326 AttributeList getRetAttributes() const;
327327
328328 /// \brief The function attributes are returned.
329 AttributeSet getFnAttributes() const;
329 AttributeList getFnAttributes() const;
330330
331331 /// \brief Return true if the attribute exists at the given index.
332332 bool hasAttribute(unsigned Index, Attribute::AttrKind Kind) const;
337337 /// \brief Return true if attribute exists at the given index.
338338 bool hasAttributes(unsigned Index) const;
339339
340 /// \brief Equivalent to hasAttribute(AttributeSet::FunctionIndex, Kind) but
340 /// \brief Equivalent to hasAttribute(AttributeList::FunctionIndex, Kind) but
341341 /// may be faster.
342342 bool hasFnAttribute(Attribute::AttrKind Kind) const;
343343
344 /// \brief Equivalent to hasAttribute(AttributeSet::FunctionIndex, Kind) but
344 /// \brief Equivalent to hasAttribute(AttributeList::FunctionIndex, Kind) but
345345 /// may be faster.
346346 bool hasFnAttribute(StringRef Kind) const;
347347
383383 iterator end(unsigned Slot) const;
384384
385385 /// operator==/!= - Provide equality predicates.
386 bool operator==(const AttributeSet &RHS) const {
387 return pImpl == RHS.pImpl;
388 }
389 bool operator!=(const AttributeSet &RHS) const {
390 return pImpl != RHS.pImpl;
391 }
392
393 //===--------------------------------------------------------------------===//
394 // AttributeSet Introspection
386 bool operator==(const AttributeList &RHS) const { return pImpl == RHS.pImpl; }
387 bool operator!=(const AttributeList &RHS) const { return pImpl != RHS.pImpl; }
388
389 //===--------------------------------------------------------------------===//
390 // AttributeList Introspection
395391 //===--------------------------------------------------------------------===//
396392
397393 /// \brief Return a raw pointer that uniquely identifies this attribute list.
413409 unsigned getSlotIndex(unsigned Slot) const;
414410
415411 /// \brief Return the attributes at the given slot.
416 AttributeSet getSlotAttributes(unsigned Slot) const;
412 AttributeList getSlotAttributes(unsigned Slot) const;
417413
418414 void dump() const;
419415 };
420416
421417 //===----------------------------------------------------------------------===//
422418 /// \class
423 /// \brief Provide DenseMapInfo for AttributeSet.
424 template<> struct DenseMapInfo {
425 static inline AttributeSet getEmptyKey() {
419 /// \brief Provide DenseMapInfo for AttributeList.
420 template <> struct DenseMapInfo {
421 static inline AttributeList getEmptyKey() {
426422 uintptr_t Val = static_cast(-1);
427423 Val <<= PointerLikeTypeTraits::NumLowBitsAvailable;
428 return AttributeSet(reinterpret_cast(Val));
429 }
430
431 static inline AttributeSet getTombstoneKey() {
424 return AttributeList(reinterpret_cast(Val));
425 }
426
427 static inline AttributeList getTombstoneKey() {
432428 uintptr_t Val = static_cast(-2);
433429 Val <<= PointerLikeTypeTraits::NumLowBitsAvailable;
434 return AttributeSet(reinterpret_cast(Val));
435 }
436
437 static unsigned getHashValue(AttributeSet AS) {
430 return AttributeList(reinterpret_cast(Val));
431 }
432
433 static unsigned getHashValue(AttributeList AS) {
438434 return (unsigned((uintptr_t)AS.pImpl) >> 4) ^
439435 (unsigned((uintptr_t)AS.pImpl) >> 9);
440436 }
441437
442 static bool isEqual(AttributeSet LHS, AttributeSet RHS) { return LHS == RHS; }
438 static bool isEqual(AttributeList LHS, AttributeList RHS) {
439 return LHS == RHS;
440 }
443441 };
444442
445443 //===----------------------------------------------------------------------===//
462460 AttrBuilder(const Attribute &A) {
463461 addAttribute(A);
464462 }
465 AttrBuilder(AttributeSet AS, unsigned Idx);
463 AttrBuilder(AttributeList AS, unsigned Idx);
466464
467465 void clear();
468466
479477 AttrBuilder &removeAttribute(Attribute::AttrKind Val);
480478
481479 /// \brief Remove the attributes from the builder.
482 AttrBuilder &removeAttributes(AttributeSet A, uint64_t Index);
480 AttrBuilder &removeAttributes(AttributeList A, uint64_t Index);
483481
484482 /// \brief Remove the target-dependent attribute to the builder.
485483 AttrBuilder &removeAttribute(StringRef A);
509507
510508 /// \brief Return true if the builder has any attribute that's in the
511509 /// specified attribute.
512 bool hasAttributes(AttributeSet A, uint64_t Index) const;
510 bool hasAttributes(AttributeList A, uint64_t Index) const;
513511
514512 /// \brief Return true if the builder has an alignment attribute.
515513 bool hasAlignmentAttr() const;
322322 }
323323
324324 /// Get the parameter attributes of the call.
325 AttributeSet getAttributes() const {
325 AttributeList getAttributes() const {
326326 CALLSITE_DELEGATE_GETTER(getAttributes());
327327 }
328328 /// Set the parameter attributes of the call.
329 void setAttributes(AttributeSet PAL) {
329 void setAttributes(AttributeList PAL) {
330330 CALLSITE_DELEGATE_SETTER(setAttributes(PAL));
331331 }
332332
6363 size_t NumArgs;
6464 std::unique_ptr
6565 SymTab; ///< Symbol table of args/instructions
66 AttributeSet AttributeSets; ///< Parameter attributes
66 AttributeList AttributeSets; ///< Parameter attributes
6767
6868 /*
6969 * Value::SubclassData
183183 }
184184
185185 /// @brief Return the attribute list for this Function.
186 AttributeSet getAttributes() const { return AttributeSets; }
186 AttributeList getAttributes() const { return AttributeSets; }
187187
188188 /// @brief Set the attribute list for this Function.
189 void setAttributes(AttributeSet Attrs) { AttributeSets = Attrs; }
189 void setAttributes(AttributeList Attrs) { AttributeSets = Attrs; }
190190
191191 /// @brief Add function attributes to this function.
192192 void addFnAttr(Attribute::AttrKind Kind) {
193 addAttribute(AttributeSet::FunctionIndex, Kind);
193 addAttribute(AttributeList::FunctionIndex, Kind);
194194 }
195195
196196 /// @brief Add function attributes to this function.
197197 void addFnAttr(StringRef Kind, StringRef Val = StringRef()) {
198 addAttribute(AttributeSet::FunctionIndex,
198 addAttribute(AttributeList::FunctionIndex,
199199 Attribute::get(getContext(), Kind, Val));
200200 }
201201
202202 void addFnAttr(Attribute Attr) {
203 addAttribute(AttributeSet::FunctionIndex, Attr);
203 addAttribute(AttributeList::FunctionIndex, Attr);
204204 }
205205
206206 /// @brief Remove function attributes from this function.
207207 void removeFnAttr(Attribute::AttrKind Kind) {
208 removeAttribute(AttributeSet::FunctionIndex, Kind);
208 removeAttribute(AttributeList::FunctionIndex, Kind);
209209 }
210210
211211 /// @brief Remove function attribute from this function.
212212 void removeFnAttr(StringRef Kind) {
213213 setAttributes(AttributeSets.removeAttribute(
214 getContext(), AttributeSet::FunctionIndex, Kind));
214 getContext(), AttributeList::FunctionIndex, Kind));
215215 }
216216
217217 /// \brief Set the entry count for this function.
249249
250250 /// @brief Return the attribute for the given attribute kind.
251251 Attribute getFnAttribute(Attribute::AttrKind Kind) const {
252 return getAttribute(AttributeSet::FunctionIndex, Kind);
252 return getAttribute(AttributeList::FunctionIndex, Kind);
253253 }
254254 Attribute getFnAttribute(StringRef Kind) const {
255 return getAttribute(AttributeSet::FunctionIndex, Kind);
255 return getAttribute(AttributeList::FunctionIndex, Kind);
256256 }
257257
258258 /// \brief Return the stack alignment for the function.
259259 unsigned getFnStackAlignment() const {
260260 if (!hasFnAttribute(Attribute::StackAlignment))
261261 return 0;
262 return AttributeSets.getStackAlignment(AttributeSet::FunctionIndex);
262 return AttributeSets.getStackAlignment(AttributeList::FunctionIndex);
263263 }
264264
265265 /// hasGC/getGC/setGC/clearGC - The name of the garbage collection algorithm
278278 void addAttribute(unsigned i, Attribute Attr);
279279
280280 /// @brief adds the attributes to the list of attributes.
281 void addAttributes(unsigned i, AttributeSet Attrs);
281 void addAttributes(unsigned i, AttributeList Attrs);
282282
283283 /// @brief removes the attribute from the list of attributes.
284284 void removeAttribute(unsigned i, Attribute::AttrKind Kind);
287287 void removeAttribute(unsigned i, StringRef Kind);
288288
289289 /// @brief removes the attributes from the list of attributes.
290 void removeAttributes(unsigned i, AttributeSet Attrs);
290 void removeAttributes(unsigned i, AttributeList Attrs);
291291
292292 /// @brief check if an attributes is in the list of attributes.
293293 bool hasAttribute(unsigned i, Attribute::AttrKind Kind) const {
13611361 public OperandBundleUser {
13621362 friend class OperandBundleUser;
13631363
1364 AttributeSet AttributeList; ///< parameter attributes for call
1364 AttributeList Attrs; ///< parameter attributes for call
13651365 FunctionType *FTy;
13661366
13671367 CallInst(const CallInst &CI);
16401640
16411641 /// Return the parameter attributes for this call.
16421642 ///
1643 AttributeSet getAttributes() const { return AttributeList; }
1643 AttributeList getAttributes() const { return Attrs; }
16441644
16451645 /// Set the parameter attributes for this call.
16461646 ///
1647 void setAttributes(AttributeSet Attrs) { AttributeList = Attrs; }
1647 void setAttributes(AttributeList A) { Attrs = A; }
16481648
16491649 /// adds the attribute to the list of attributes.
16501650 void addAttribute(unsigned i, Attribute::AttrKind Kind);
17071707
17081708 /// Extract the alignment for a call or parameter (0=unknown).
17091709 unsigned getParamAlignment(unsigned i) const {
1710 return AttributeList.getParamAlignment(i);
1710 return Attrs.getParamAlignment(i);
17111711 }
17121712
17131713 /// Extract the number of dereferenceable bytes for a call or
17141714 /// parameter (0=unknown).
17151715 uint64_t getDereferenceableBytes(unsigned i) const {
1716 return AttributeList.getDereferenceableBytes(i);
1716 return Attrs.getDereferenceableBytes(i);
17171717 }
17181718
17191719 /// Extract the number of dereferenceable_or_null bytes for a call or
17201720 /// parameter (0=unknown).
17211721 uint64_t getDereferenceableOrNullBytes(unsigned i) const {
1722 return AttributeList.getDereferenceableOrNullBytes(i);
1722 return Attrs.getDereferenceableOrNullBytes(i);
17231723 }
17241724
17251725 /// @brief Determine if the parameter or return value is marked with NoAlias
17261726 /// attribute.
17271727 /// @param n The parameter to check. 1 is the first parameter, 0 is the return
17281728 bool doesNotAlias(unsigned n) const {
1729 return AttributeList.hasAttribute(n, Attribute::NoAlias);
1729 return Attrs.hasAttribute(n, Attribute::NoAlias);
17301730 }
17311731
17321732 /// Return true if the call should not be treated as a call to a
17391739 /// Return true if the call should not be inlined.
17401740 bool isNoInline() const { return hasFnAttr(Attribute::NoInline); }
17411741 void setIsNoInline() {
1742 addAttribute(AttributeSet::FunctionIndex, Attribute::NoInline);
1742 addAttribute(AttributeList::FunctionIndex, Attribute::NoInline);
17431743 }
17441744
17451745 /// Return true if the call can return twice
17471747 return hasFnAttr(Attribute::ReturnsTwice);
17481748 }
17491749 void setCanReturnTwice() {
1750 addAttribute(AttributeSet::FunctionIndex, Attribute::ReturnsTwice);
1750 addAttribute(AttributeList::FunctionIndex, Attribute::ReturnsTwice);
17511751 }
17521752
17531753 /// Determine if the call does not access memory.
17551755 return hasFnAttr(Attribute::ReadNone);
17561756 }
17571757 void setDoesNotAccessMemory() {
1758 addAttribute(AttributeSet::FunctionIndex, Attribute::ReadNone);
1758 addAttribute(AttributeList::FunctionIndex, Attribute::ReadNone);
17591759 }
17601760
17611761 /// Determine if the call does not access or only reads memory.
17631763 return doesNotAccessMemory() || hasFnAttr(Attribute::ReadOnly);
17641764 }
17651765 void setOnlyReadsMemory() {
1766 addAttribute(AttributeSet::FunctionIndex, Attribute::ReadOnly);
1766 addAttribute(AttributeList::FunctionIndex, Attribute::ReadOnly);
17671767 }
17681768
17691769 /// Determine if the call does not access or only writes memory.
17711771 return doesNotAccessMemory() || hasFnAttr(Attribute::WriteOnly);
17721772 }
17731773 void setDoesNotReadMemory() {
1774 addAttribute(AttributeSet::FunctionIndex, Attribute::WriteOnly);
1774 addAttribute(AttributeList::FunctionIndex, Attribute::WriteOnly);
17751775 }
17761776
17771777 /// @brief Determine if the call can access memmory only using pointers based
17801780 return hasFnAttr(Attribute::ArgMemOnly);
17811781 }
17821782 void setOnlyAccessesArgMemory() {
1783 addAttribute(AttributeSet::FunctionIndex, Attribute::ArgMemOnly);
1783 addAttribute(AttributeList::FunctionIndex, Attribute::ArgMemOnly);
17841784 }
17851785
17861786 /// Determine if the call cannot return.
17871787 bool doesNotReturn() const { return hasFnAttr(Attribute::NoReturn); }
17881788 void setDoesNotReturn() {
1789 addAttribute(AttributeSet::FunctionIndex, Attribute::NoReturn);
1789 addAttribute(AttributeList::FunctionIndex, Attribute::NoReturn);
17901790 }
17911791
17921792 /// Determine if the call cannot unwind.
17931793 bool doesNotThrow() const { return hasFnAttr(Attribute::NoUnwind); }
17941794 void setDoesNotThrow() {
1795 addAttribute(AttributeSet::FunctionIndex, Attribute::NoUnwind);
1795 addAttribute(AttributeList::FunctionIndex, Attribute::NoUnwind);
17961796 }
17971797
17981798 /// Determine if the call cannot be duplicated.
17991799 bool cannotDuplicate() const {return hasFnAttr(Attribute::NoDuplicate); }
18001800 void setCannotDuplicate() {
1801 addAttribute(AttributeSet::FunctionIndex, Attribute::NoDuplicate);
1801 addAttribute(AttributeList::FunctionIndex, Attribute::NoDuplicate);
18021802 }
18031803
18041804 /// Determine if the call is convergent
18051805 bool isConvergent() const { return hasFnAttr(Attribute::Convergent); }
18061806 void setConvergent() {
1807 addAttribute(AttributeSet::FunctionIndex, Attribute::Convergent);
1807 addAttribute(AttributeList::FunctionIndex, Attribute::Convergent);
18081808 }
18091809 void setNotConvergent() {
1810 removeAttribute(AttributeSet::FunctionIndex, Attribute::Convergent);
1810 removeAttribute(AttributeList::FunctionIndex, Attribute::Convergent);
18111811 }
18121812
18131813 /// Determine if the call returns a structure through first
18221822
18231823 /// Determine if any call argument is an aggregate passed by value.
18241824 bool hasByValArgument() const {
1825 return AttributeList.hasAttrSomewhere(Attribute::ByVal);
1825 return Attrs.hasAttrSomewhere(Attribute::ByVal);
18261826 }
18271827
18281828 /// Return the function called, or null if this is an
18651865
18661866 private:
18671867 template bool hasFnAttrImpl(AttrKind Kind) const {
1868 if (AttributeList.hasAttribute(AttributeSet::FunctionIndex, Kind))
1868 if (Attrs.hasAttribute(AttributeList::FunctionIndex, Kind))
18691869 return true;
18701870
18711871 // Operand bundles override attributes on the called function, but don't
18741874 return false;
18751875
18761876 if (const Function *F = getCalledFunction())
1877 return F->getAttributes().hasAttribute(AttributeSet::FunctionIndex, Kind);
1877 return F->getAttributes().hasAttribute(AttributeList::FunctionIndex,
1878 Kind);
18781879 return false;
18791880 }
18801881
34723473 public OperandBundleUser {
34733474 friend class OperandBundleUser;
34743475
3475 AttributeSet AttributeList;
3476 AttributeList Attrs;
34763477 FunctionType *FTy;
34773478
34783479 InvokeInst(const InvokeInst &BI);
36763677
36773678 /// Return the parameter attributes for this invoke.
36783679 ///
3679 AttributeSet getAttributes() const { return AttributeList; }
3680 AttributeList getAttributes() const { return Attrs; }
36803681
36813682 /// Set the parameter attributes for this invoke.
36823683 ///
3683 void setAttributes(AttributeSet Attrs) { AttributeList = Attrs; }
3684 void setAttributes(AttributeList A) { Attrs = A; }
36843685
36853686 /// adds the attribute to the list of attributes.
36863687 void addAttribute(unsigned i, Attribute::AttrKind Kind);
37443745
37453746 /// Extract the alignment for a call or parameter (0=unknown).
37463747 unsigned getParamAlignment(unsigned i) const {
3747 return AttributeList.getParamAlignment(i);
3748 return Attrs.getParamAlignment(i);
37483749 }
37493750
37503751 /// Extract the number of dereferenceable bytes for a call or
37513752 /// parameter (0=unknown).
37523753 uint64_t getDereferenceableBytes(unsigned i) const {
3753 return AttributeList.getDereferenceableBytes(i);
3754 return Attrs.getDereferenceableBytes(i);
37543755 }
37553756
37563757 /// Extract the number of dereferenceable_or_null bytes for a call or
37573758 /// parameter (0=unknown).
37583759 uint64_t getDereferenceableOrNullBytes(unsigned i) const {
3759 return AttributeList.getDereferenceableOrNullBytes(i);
3760 return Attrs.getDereferenceableOrNullBytes(i);
37603761 }
37613762
37623763 /// @brief Determine if the parameter or return value is marked with NoAlias
37633764 /// attribute.
37643765 /// @param n The parameter to check. 1 is the first parameter, 0 is the return
37653766 bool doesNotAlias(unsigned n) const {
3766 return AttributeList.hasAttribute(n, Attribute::NoAlias);
3767 return Attrs.hasAttribute(n, Attribute::NoAlias);
37673768 }
37683769
37693770 /// Return true if the call should not be treated as a call to a
37783779 /// Return true if the call should not be inlined.
37793780 bool isNoInline() const { return hasFnAttr(Attribute::NoInline); }
37803781 void setIsNoInline() {
3781 addAttribute(AttributeSet::FunctionIndex, Attribute::NoInline);
3782 addAttribute(AttributeList::FunctionIndex, Attribute::NoInline);
37823783 }
37833784
37843785 /// Determine if the call does not access memory.
37863787 return hasFnAttr(Attribute::ReadNone);
37873788 }
37883789 void setDoesNotAccessMemory() {
3789 addAttribute(AttributeSet::FunctionIndex, Attribute::ReadNone);
3790 addAttribute(AttributeList::FunctionIndex, Attribute::ReadNone);
37903791 }
37913792
37923793 /// Determine if the call does not access or only reads memory.
37943795 return doesNotAccessMemory() || hasFnAttr(Attribute::ReadOnly);
37953796 }
37963797 void setOnlyReadsMemory() {
3797 addAttribute(AttributeSet::FunctionIndex, Attribute::ReadOnly);
3798 addAttribute(AttributeList::FunctionIndex, Attribute::ReadOnly);
37983799 }
37993800
38003801 /// Determine if the call does not access or only writes memory.
38023803 return doesNotAccessMemory() || hasFnAttr(Attribute::WriteOnly);
38033804 }
38043805 void setDoesNotReadMemory() {
3805 addAttribute(AttributeSet::FunctionIndex, Attribute::WriteOnly);
3806 addAttribute(AttributeList::FunctionIndex, Attribute::WriteOnly);
38063807 }
38073808
38083809 /// @brief Determine if the call access memmory only using it's pointer
38113812 return hasFnAttr(Attribute::ArgMemOnly);
38123813 }
38133814 void setOnlyAccessesArgMemory() {
3814 addAttribute(AttributeSet::FunctionIndex, Attribute::ArgMemOnly);
3815 addAttribute(AttributeList::FunctionIndex, Attribute::ArgMemOnly);
38153816 }
38163817
38173818 /// Determine if the call cannot return.
38183819 bool doesNotReturn() const { return hasFnAttr(Attribute::NoReturn); }
38193820 void setDoesNotReturn() {
3820 addAttribute(AttributeSet::FunctionIndex, Attribute::NoReturn);
3821 addAttribute(AttributeList::FunctionIndex, Attribute::NoReturn);
38213822 }
38223823
38233824 /// Determine if the call cannot unwind.
38243825 bool doesNotThrow() const { return hasFnAttr(Attribute::NoUnwind); }
38253826 void setDoesNotThrow() {
3826 addAttribute(AttributeSet::FunctionIndex, Attribute::NoUnwind);
3827 addAttribute(AttributeList::FunctionIndex, Attribute::NoUnwind);
38273828 }
38283829
38293830 /// Determine if the invoke cannot be duplicated.
38303831 bool cannotDuplicate() const {return hasFnAttr(Attribute::NoDuplicate); }
38313832 void setCannotDuplicate() {
3832 addAttribute(AttributeSet::FunctionIndex, Attribute::NoDuplicate);
3833 addAttribute(AttributeList::FunctionIndex, Attribute::NoDuplicate);
38333834 }
38343835
38353836 /// Determine if the invoke is convergent
38363837 bool isConvergent() const { return hasFnAttr(Attribute::Convergent); }
38373838 void setConvergent() {
3838 addAttribute(AttributeSet::FunctionIndex, Attribute::Convergent);
3839 addAttribute(AttributeList::FunctionIndex, Attribute::Convergent);
38393840 }
38403841 void setNotConvergent() {
3841 removeAttribute(AttributeSet::FunctionIndex, Attribute::Convergent);
3842 removeAttribute(AttributeList::FunctionIndex, Attribute::Convergent);
38423843 }
38433844
38443845 /// Determine if the call returns a structure through first
38533854
38543855 /// Determine if any call argument is an aggregate passed by value.
38553856 bool hasByValArgument() const {
3856 return AttributeList.hasAttrSomewhere(Attribute::ByVal);
3857 return Attrs.hasAttrSomewhere(Attribute::ByVal);
38573858 }
38583859
38593860 /// Return the function called, or null if this is an
39253926 void setSuccessorV(unsigned idx, BasicBlock *B) override;
39263927
39273928 template bool hasFnAttrImpl(AttrKind Kind) const {
3928 if (AttributeList.hasAttribute(AttributeSet::FunctionIndex, Kind))
3929 if (Attrs.hasAttribute(AttributeList::FunctionIndex, Kind))
39293930 return true;
39303931
39313932 // Operand bundles override attributes on the called function, but don't
39343935 return false;
39353936
39363937 if (const Function *F = getCalledFunction())
3937 return F->getAttributes().hasAttribute(AttributeSet::FunctionIndex, Kind);
3938 return F->getAttributes().hasAttribute(AttributeList::FunctionIndex,
3939 Kind);
39383940 return false;
39393941 }
39403942
2727 class Function;
2828 class LLVMContext;
2929 class Module;
30 class AttributeSet;
30 class AttributeList;
3131
3232 /// This namespace contains an enum with a value for every intrinsic/builtin
3333 /// function known by LLVM. The enum values are returned by
6868 bool isLeaf(ID id);
6969
7070 /// Return the attributes for an intrinsic.
71 AttributeSet getAttributes(LLVMContext &C, ID id);
71 AttributeList getAttributes(LLVMContext &C, ID id);
7272
7373 /// Create or insert an LLVM Function declaration for an intrinsic, and return
7474 /// it.
310310 /// 4. Finally, the function exists but has the wrong prototype: return the
311311 /// function with a constantexpr cast to the right prototype.
312312 Constant *getOrInsertFunction(StringRef Name, FunctionType *T,
313 AttributeSet AttributeList);
313 AttributeList AttributeList);
314314
315315 Constant *getOrInsertFunction(StringRef Name, FunctionType *T);
316316
320320 /// or a ConstantExpr BitCast of that type if the named function has a
321321 /// different type. This version of the method takes a null terminated list of
322322 /// function arguments, which makes it easier for clients to use.
323 Constant *getOrInsertFunction(StringRef Name,
324 AttributeSet AttributeList,
323 Constant *getOrInsertFunction(StringRef Name, AttributeList AttributeList,
325324 Type *RetTy, ...) LLVM_END_WITH_NULL;
326325
327326 /// Same as above, but without the attributes.
453453
454454 /// Parse out statepoint directives from the function attributes present in \p
455455 /// AS.
456 StatepointDirectives parseStatepointDirectivesFromAttrs(AttributeSet AS);
456 StatepointDirectives parseStatepointDirectivesFromAttrs(AttributeList AS);
457457
458458 /// Return \c true if the the \p Attr is an attribute that is a statepoint
459459 /// directive.
283283 /// several shifts, adds, and multiplies for this target.
284284 /// The definition of "cheaper" may depend on whether we're optimizing
285285 /// for speed or for size.
286 virtual bool isIntDivCheap(EVT VT, AttributeSet Attr) const {
287 return false;
288 }
286 virtual bool isIntDivCheap(EVT VT, AttributeList Attr) const { return false; }
289287
290288 /// Return true if the target can handle a standalone remainder operation.
291289 virtual bool hasStandaloneRem(EVT VT) const {
32163214 /// Given an LLVM IR type and return type attributes, compute the return value
32173215 /// EVTs and flags, and optionally also the offsets, if the return value is
32183216 /// being lowered to memory.
3219 void GetReturnInfo(Type *ReturnType, AttributeSet attr,
3217 void GetReturnInfo(Type *ReturnType, AttributeList attr,
32203218 SmallVectorImpl &Outs,
32213219 const TargetLowering &TLI, const DataLayout &DL);
32223220
8383 /// value with the same type. If 'Op' is a long double, 'l' is added as the
8484 /// suffix of name, if 'Op' is a float, we add a 'f' suffix.
8585 Value *emitUnaryFloatFnCall(Value *Op, StringRef Name, IRBuilder<> &B,
86 const AttributeSet &Attrs);
86 const AttributeList &Attrs);
8787
8888 /// Emit a call to the binary function named 'Name' (e.g. 'fmin'). This
8989 /// function is known to take type matching 'Op1' and 'Op2' and return one
9090 /// value with the same type. If 'Op1/Op2' are long double, 'l' is added as
9191 /// the suffix of name, if 'Op1/Op2' are float, we add a 'f' suffix.
9292 Value *emitBinaryFloatFnCall(Value *Op1, Value *Op2, StringRef Name,
93 IRBuilder<> &B, const AttributeSet &Attrs);
93 IRBuilder<> &B, const AttributeList &Attrs);
9494
9595 /// Emit a call to the putchar function. This assumes that Char is an integer.
9696 Value *emitPutChar(Value *Char, IRBuilder<> &B, const TargetLibraryInfo *TLI);
313313 private:
314314 int cmpOrderings(AtomicOrdering L, AtomicOrdering R) const;
315315 int cmpInlineAsm(const InlineAsm *L, const InlineAsm *R) const;
316 int cmpAttrs(const AttributeSet L, const AttributeSet R) const;
316 int cmpAttrs(const AttributeList L, const AttributeList R) const;
317317 int cmpRangeMetadata(const MDNode *L, const MDNode *R) const;
318318 int cmpOperandBundlesSchema(const Instruction *L, const Instruction *R) const;
319319
182182
183183 static bool hasNoAliasAttr(const Value *V, bool LookThroughBitCast) {
184184 ImmutableCallSite CS(LookThroughBitCast ? V->stripPointerCasts() : V);
185 return CS && CS.paramHasAttr(AttributeSet::ReturnIndex, Attribute::NoAlias);
185 return CS && CS.paramHasAttr(AttributeList::ReturnIndex, Attribute::NoAlias);
186186 }
187187
188188
129129 B.merge(NumberedAttrBuilders[Attr]);
130130
131131 if (Function *Fn = dyn_cast(V)) {
132 AttributeSet AS = Fn->getAttributes();
133 AttrBuilder FnAttrs(AS.getFnAttributes(), AttributeSet::FunctionIndex);
134 AS = AS.removeAttributes(Context, AttributeSet::FunctionIndex,
132 AttributeList AS = Fn->getAttributes();
133 AttrBuilder FnAttrs(AS.getFnAttributes(), AttributeList::FunctionIndex);
134 AS = AS.removeAttributes(Context, AttributeList::FunctionIndex,
135135 AS.getFnAttributes());
136136
137137 FnAttrs.merge(B);
143143 FnAttrs.removeAttribute(Attribute::Alignment);
144144 }
145145
146 AS = AS.addAttributes(Context, AttributeSet::FunctionIndex,
147 AttributeSet::get(Context,
148 AttributeSet::FunctionIndex,
149 FnAttrs));
146 AS = AS.addAttributes(
147 Context, AttributeList::FunctionIndex,
148 AttributeList::get(Context, AttributeList::FunctionIndex, FnAttrs));
150149 Fn->setAttributes(AS);
151150 } else if (CallInst *CI = dyn_cast(V)) {
152 AttributeSet AS = CI->getAttributes();
153 AttrBuilder FnAttrs(AS.getFnAttributes(), AttributeSet::FunctionIndex);
154 AS = AS.removeAttributes(Context, AttributeSet::FunctionIndex,
151 AttributeList AS = CI->getAttributes();
152 AttrBuilder FnAttrs(AS.getFnAttributes(), AttributeList::FunctionIndex);
153 AS = AS.removeAttributes(Context, AttributeList::FunctionIndex,
155154 AS.getFnAttributes());
156155 FnAttrs.merge(B);
157 AS = AS.addAttributes(Context, AttributeSet::FunctionIndex,
158 AttributeSet::get(Context,
159 AttributeSet::FunctionIndex,
160 FnAttrs));
156 AS = AS.addAttributes(
157 Context, AttributeList::FunctionIndex,
158 AttributeList::get(Context, AttributeList::FunctionIndex, FnAttrs));
161159 CI->setAttributes(AS);
162160 } else if (InvokeInst *II = dyn_cast(V)) {
163 AttributeSet AS = II->getAttributes();
164 AttrBuilder FnAttrs(AS.getFnAttributes(), AttributeSet::FunctionIndex);
165 AS = AS.removeAttributes(Context, AttributeSet::FunctionIndex,
161 AttributeList AS = II->getAttributes();
162 AttrBuilder FnAttrs(AS.getFnAttributes(), AttributeList::FunctionIndex);
163 AS = AS.removeAttributes(Context, AttributeList::FunctionIndex,
166164 AS.getFnAttributes());
167165 FnAttrs.merge(B);
168 AS = AS.addAttributes(Context, AttributeSet::FunctionIndex,
169 AttributeSet::get(Context,
170 AttributeSet::FunctionIndex,
171 FnAttrs));
166 AS = AS.addAttributes(
167 Context, AttributeList::FunctionIndex,
168 AttributeList::get(Context, AttributeList::FunctionIndex, FnAttrs));
172169 II->setAttributes(AS);
173170 } else {
174171 llvm_unreachable("invalid object with forward attribute group reference");
21312128 if (ParseOptionalParamAttrs(ArgAttrs) || ParseValue(ArgTy, V, PFS))
21322129 return true;
21332130 }
2134 ArgList.push_back(ParamInfo(ArgLoc, V, AttributeSet::get(V->getContext(),
2135 AttrIndex++,
2136 ArgAttrs)));
2131 ArgList.push_back(ParamInfo(
2132 ArgLoc, V, AttributeList::get(V->getContext(), AttrIndex++, ArgAttrs)));
21372133 }
21382134
21392135 if (IsMustTailCall && InVarArgsFunc)
22392235 return Error(TypeLoc, "invalid type for function argument");
22402236
22412237 unsigned AttrIndex = 1;
2242 ArgList.emplace_back(TypeLoc, ArgTy, AttributeSet::get(ArgTy->getContext(),
2243 AttrIndex++, Attrs),
2238 ArgList.emplace_back(TypeLoc, ArgTy, AttributeList::get(ArgTy->getContext(),
2239 AttrIndex++, Attrs),
22442240 std::move(Name));
22452241
22462242 while (EatIfPresent(lltok::comma)) {
22692265
22702266 ArgList.emplace_back(
22712267 TypeLoc, ArgTy,
2272 AttributeSet::get(ArgTy->getContext(), AttrIndex++, Attrs),
2268 AttributeList::get(ArgTy->getContext(), AttrIndex++, Attrs),
22732269 std::move(Name));
22742270 }
22752271 }
47404736 // Okay, if we got here, the function is syntactically valid. Convert types
47414737 // and do semantic checks.
47424738 std::vector ParamTypeList;
4743 SmallVectorSet, 8> Attrs;
4739 SmallVectorList, 8> Attrs;
47444740
47454741 if (RetAttrs.hasAttributes())
4746 Attrs.push_back(AttributeSet::get(RetType->getContext(),
4747 AttributeSet::ReturnIndex,
4748 RetAttrs));
4742 Attrs.push_back(AttributeList::get(RetType->getContext(),
4743 AttributeList::ReturnIndex, RetAttrs));
47494744
47504745 for (unsigned i = 0, e = ArgList.size(); i != e; ++i) {
47514746 ParamTypeList.push_back(ArgList[i].Ty);
47524747 if (ArgList[i].Attrs.hasAttributes(i + 1)) {
47534748 AttrBuilder B(ArgList[i].Attrs, i + 1);
4754 Attrs.push_back(AttributeSet::get(RetType->getContext(), i + 1, B));
4749 Attrs.push_back(AttributeList::get(RetType->getContext(), i + 1, B));
47554750 }
47564751 }
47574752
47584753 if (FuncAttrs.hasAttributes())
4759 Attrs.push_back(AttributeSet::get(RetType->getContext(),
4760 AttributeSet::FunctionIndex,
4761 FuncAttrs));
4762
4763 AttributeSet PAL = AttributeSet::get(Context, Attrs);
4754 Attrs.push_back(AttributeList::get(
4755 RetType->getContext(), AttributeList::FunctionIndex, FuncAttrs));
4756
4757 AttributeList PAL = AttributeList::get(Context, Attrs);
47644758
47654759 if (PAL.hasAttribute(1, Attribute::StructRet) && !RetType->isVoidTy())
47664760 return Error(RetTypeLoc, "functions with 'sret' argument must return void");
53705364 return true;
53715365
53725366 // Set up the Attribute for the function.
5373 SmallVectorSet, 8> Attrs;
5367 SmallVectorList, 8> Attrs;
53745368 if (RetAttrs.hasAttributes())
5375 Attrs.push_back(AttributeSet::get(RetType->getContext(),
5376 AttributeSet::ReturnIndex,
5377 RetAttrs));
5369 Attrs.push_back(AttributeList::get(RetType->getContext(),
5370 AttributeList::ReturnIndex, RetAttrs));
53785371
53795372 SmallVector Args;
53805373
53965389 Args.push_back(ArgList[i].V);
53975390 if (ArgList[i].Attrs.hasAttributes(i + 1)) {
53985391 AttrBuilder B(ArgList[i].Attrs, i + 1);
5399 Attrs.push_back(AttributeSet::get(RetType->getContext(), i + 1, B));
5392 Attrs.push_back(AttributeList::get(RetType->getContext(), i + 1, B));
54005393 }
54015394 }
54025395
54075400 if (FnAttrs.hasAlignmentAttr())
54085401 return Error(CallLoc, "invoke instructions may not have an alignment");
54095402
5410 Attrs.push_back(AttributeSet::get(RetType->getContext(),
5411 AttributeSet::FunctionIndex,
5412 FnAttrs));
5403 Attrs.push_back(AttributeList::get(RetType->getContext(),
5404 AttributeList::FunctionIndex, FnAttrs));
54135405 }
54145406
54155407 // Finish off the Attribute and check them
5416 AttributeSet PAL = AttributeSet::get(Context, Attrs);
5408 AttributeList PAL = AttributeList::get(Context, Attrs);
54175409
54185410 InvokeInst *II =
54195411 InvokeInst::Create(Ty, Callee, NormalBB, UnwindBB, Args, BundleList);
59745966 return true;
59755967
59765968 // Set up the Attribute for the function.
5977 SmallVectorSet, 8> Attrs;
5969 SmallVectorList, 8> Attrs;
59785970 if (RetAttrs.hasAttributes())
5979 Attrs.push_back(AttributeSet::get(RetType->getContext(),
5980 AttributeSet::ReturnIndex,
5981 RetAttrs));
5971 Attrs.push_back(AttributeList::get(RetType->getContext(),
5972 AttributeList::ReturnIndex, RetAttrs));
59825973
59835974 SmallVector Args;
59845975
60005991 Args.push_back(ArgList[i].V);
60015992 if (ArgList[i].Attrs.hasAttributes(i + 1)) {
60025993 AttrBuilder B(ArgList[i].Attrs, i + 1);
6003 Attrs.push_back(AttributeSet::get(RetType->getContext(), i + 1, B));
5994 Attrs.push_back(AttributeList::get(RetType->getContext(), i + 1, B));
60045995 }
60055996 }
60065997
60116002 if (FnAttrs.hasAlignmentAttr())
60126003 return Error(CallLoc, "call instructions may not have an alignment");
60136004
6014 Attrs.push_back(AttributeSet::get(RetType->getContext(),
6015 AttributeSet::FunctionIndex,
6016 FnAttrs));
6005 Attrs.push_back(AttributeList::get(RetType->getContext(),
6006 AttributeList::FunctionIndex, FnAttrs));
60176007 }
60186008
60196009 // Finish off the Attribute and check them
6020 AttributeSet PAL = AttributeSet::get(Context, Attrs);
6010 AttributeList PAL = AttributeList::get(Context, Attrs);
60216011
60226012 CallInst *CI = CallInst::Create(Ty, Callee, Args, BundleList);
60236013 CI->setTailCallKind(TCK);
390390 struct ParamInfo {
391391 LocTy Loc;
392392 Value *V;
393 AttributeSet Attrs;
394 ParamInfo(LocTy loc, Value *v, AttributeSet attrs)
395 : Loc(loc), V(v), Attrs(attrs) {}
393 AttributeList Attrs;
394 ParamInfo(LocTy loc, Value *v, AttributeList attrs)
395 : Loc(loc), V(v), Attrs(attrs) {}
396396 };
397397 bool ParseParameterList(SmallVectorImpl &ArgList,
398398 PerFunctionState &PFS,
443443 struct ArgInfo {
444444 LocTy Loc;
445445 Type *Ty;
446 AttributeSet Attrs;
446 AttributeList Attrs;
447447 std::string Name;
448 ArgInfo(LocTy L, Type *ty, AttributeSet Attr, const std::string &N)
449 : Loc(L), Ty(ty), Attrs(Attr), Name(N) {}
448 ArgInfo(LocTy L, Type *ty, AttributeList Attr, const std::string &N)
449 : Loc(L), Ty(ty), Attrs(Attr), Name(N) {}
450450 };
451451 bool ParseArgumentList(SmallVectorImpl &ArgList, bool &isVarArg);
452452 bool ParseFunctionHeader(Function *&Fn, bool isDefine);
418418
419419 /// The set of attributes by index. Index zero in the file is for null, and
420420 /// is thus not represented here. As such all indices are off by one.
421 std::vectorSet> MAttributes;
421 std::vectorList> MAttributes;
422422
423423 /// The set of attribute groups.
424 std::mapSet> MAttributeGroups;
424 std::mapList> MAttributeGroups;
425425
426426 /// While parsing a function body, this is a list of the basic blocks for the
427427 /// function.
519519 return FunctionBBs[ID];
520520 }
521521
522 AttributeSet getAttributes(unsigned i) const {
522 AttributeList getAttributes(unsigned i) const {
523523 if (i-1 < MAttributes.size())
524524 return MAttributes[i-1];
525 return AttributeSet();
525 return AttributeList();
526526 }
527527
528528 /// Read a value/type pair out of the specified record from slot 'Slot'.
11311131
11321132 SmallVector Record;
11331133
1134 SmallVectorSet, 8> Attrs;
1134 SmallVectorList, 8> Attrs;
11351135
11361136 // Read all the records.
11371137 while (true) {
11611161 for (unsigned i = 0, e = Record.size(); i != e; i += 2) {
11621162 AttrBuilder B;
11631163 decodeLLVMAttributesForBitcode(B, Record[i+1]);
1164 Attrs.push_back(AttributeSet::get(Context, Record[i], B));
1165 }
1166
1167 MAttributes.push_back(AttributeSet::get(Context, Attrs));
1164 Attrs.push_back(AttributeList::get(Context, Record[i], B));
1165 }
1166
1167 MAttributes.push_back(AttributeList::get(Context, Attrs));
11681168 Attrs.clear();
11691169 break;
11701170 }
11721172 for (unsigned i = 0, e = Record.size(); i != e; ++i)
11731173 Attrs.push_back(MAttributeGroups[Record[i]]);
11741174
1175 MAttributes.push_back(AttributeSet::get(Context, Attrs));
1175 MAttributes.push_back(AttributeList::get(Context, Attrs));
11761176 Attrs.clear();
11771177 break;
11781178 }
13901390 }
13911391 }
13921392
1393 MAttributeGroups[GrpID] = AttributeSet::get(Context, Idx, B);
1393 MAttributeGroups[GrpID] = AttributeList::get(Context, Idx, B);
13941394 break;
13951395 }
13961396 }
38393839 if (Record.size() < 4)
38403840 return error("Invalid record");
38413841 unsigned OpNum = 0;
3842 AttributeSet PAL = getAttributes(Record[OpNum++]);
3842 AttributeList PAL = getAttributes(Record[OpNum++]);
38433843 unsigned CCInfo = Record[OpNum++];
38443844 BasicBlock *NormalBB = getBasicBlock(Record[OpNum++]);
38453845 BasicBlock *UnwindBB = getBasicBlock(Record[OpNum++]);
42244224 return error("Invalid record");
42254225
42264226 unsigned OpNum = 0;
4227 AttributeSet PAL = getAttributes(Record[OpNum++]);
4227 AttributeList PAL = getAttributes(Record[OpNum++]);
42284228 unsigned CCInfo = Record[OpNum++];
42294229
42304230 FastMathFlags FMF;
708708 }
709709
710710 void ModuleBitcodeWriter::writeAttributeGroupTable() {
711 const std::vectorSet> &AttrGrps = VE.getAttributeGroups();
711 const std::vectorList> &AttrGrps = VE.getAttributeGroups();
712712 if (AttrGrps.empty()) return;
713713
714714 Stream.EnterSubblock(bitc::PARAMATTR_GROUP_BLOCK_ID, 3);
715715
716716 SmallVector Record;
717717 for (unsigned i = 0, e = AttrGrps.size(); i != e; ++i) {
718 AttributeSet AS = AttrGrps[i];
718 AttributeList AS = AttrGrps[i];
719719 for (unsigned i = 0, e = AS.getNumSlots(); i != e; ++i) {
720 AttributeSet A = AS.getSlotAttributes(i);
720 AttributeList A = AS.getSlotAttributes(i);
721721
722722 Record.push_back(VE.getAttributeGroupID(A));
723723 Record.push_back(AS.getSlotIndex(i));
724724
725 for (AttributeSet::iterator I = AS.begin(0), E = AS.end(0);
726 I != E; ++I) {
725 for (AttributeList::iterator I = AS.begin(0), E = AS.end(0); I != E;
726 ++I) {
727727 Attribute Attr = *I;
728728 if (Attr.isEnumAttribute()) {
729729 Record.push_back(0);
755755 }
756756
757757 void ModuleBitcodeWriter::writeAttributeTable() {
758 const std::vectorSet> &Attrs = VE.getAttributes();
758 const std::vectorList> &Attrs = VE.getAttributes();
759759 if (Attrs.empty()) return;
760760
761761 Stream.EnterSubblock(bitc::PARAMATTR_BLOCK_ID, 3);
762762
763763 SmallVector Record;
764764 for (unsigned i = 0, e = Attrs.size(); i != e; ++i) {
765 const AttributeSet &A = Attrs[i];
765 const AttributeList &A = Attrs[i];
766766 for (unsigned i = 0, e = A.getNumSlots(); i != e; ++i)
767767 Record.push_back(VE.getAttributeGroupID(A.getSlotAttributes(i)));
768768
886886 }
887887 }
888888
889 void ValueEnumerator::EnumerateAttributes(AttributeSet PAL) {
889 void ValueEnumerator::EnumerateAttributes(AttributeList PAL) {
890890 if (PAL.isEmpty()) return; // null is always 0.
891891
892892 // Do a lookup.
899899
900900 // Do lookups for all attribute groups.
901901 for (unsigned i = 0, e = PAL.getNumSlots(); i != e; ++i) {
902 AttributeSet AS = PAL.getSlotAttributes(i);
902 AttributeList AS = PAL.getSlotAttributes(i);
903903 unsigned &Entry = AttributeGroupMap[AS];
904904 if (Entry == 0) {
905905 AttributeGroups.push_back(AS);
3535 class MDNode;
3636 class MDOperand;
3737 class NamedMDNode;
38 class AttributeSet;
38 class AttributeList;
3939 class ValueSymbolTable;
4040 class MDSymbolTable;
4141 class raw_ostream;
101101
102102 bool ShouldPreserveUseListOrder;
103103
104 typedef DenseMapSet, unsigned> AttributeGroupMapType;
104 typedef DenseMapList, unsigned> AttributeGroupMapType;
105105 AttributeGroupMapType AttributeGroupMap;
106 std::vector AttributeGroups;
107
108 typedef DenseMap AttributeMapType;
106 std::vector AttributeGroups;
107
108 typedef DenseMap AttributeMapType;
109109 AttributeMapType AttributeMap;
110 std::vectorSet> Attribute;
110 std::vectorList> Attribute;
111111
112112 /// GlobalBasicBlockIDs - This map memoizes the basic block ID's referenced by
113113 /// the "getGlobalBasicBlockID" method.
165165 unsigned getInstructionID(const Instruction *I) const;
166166 void setInstructionID(const Instruction *I);
167167
168 unsigned getAttributeID(AttributeSet PAL) const {
168 unsigned getAttributeID(AttributeList PAL) const {
169169 if (PAL.isEmpty()) return 0; // Null maps to zero.
170170 AttributeMapType::const_iterator I = AttributeMap.find(PAL);
171171 assert(I != AttributeMap.end() && "Attribute not in ValueEnumerator!");
172172 return I->second;
173173 }
174174
175 unsigned getAttributeGroupID(AttributeSet PAL) const {
175 unsigned getAttributeGroupID(AttributeList PAL) const {
176176 if (PAL.isEmpty()) return 0; // Null maps to zero.
177177 AttributeGroupMapType::const_iterator I = AttributeGroupMap.find(PAL);
178178 assert(I != AttributeGroupMap.end() && "Attribute not in ValueEnumerator!");
205205 const std::vector &getBasicBlocks() const {
206206 return BasicBlocks;
207207 }
208 const std::vector &getAttributes() const {
209 return Attribute;
210 }
211 const std::vectorSet> &getAttributeGroups() const {
208 const std::vectorList> &getAttributes() const { return Attribute; }
209 const std::vector &getAttributeGroups() const {
212210 return AttributeGroups;
213211 }
214212
282280 void EnumerateValue(const Value *V);
283281 void EnumerateType(Type *T);
284282 void EnumerateOperandType(const Value *V);
285 void EnumerateAttributes(AttributeSet PAL);
283 void EnumerateAttributes(AttributeList PAL);
286284
287285 void EnumerateValueSymbolTable(const ValueSymbolTable &ST);
288286 void EnumerateNamedMetadata(const Module &M);
515515 bool &ADS = AllowDifferingSizes ? *AllowDifferingSizes : DummyADS;
516516 ADS = true;
517517
518 AttrBuilder CallerAttrs(F->getAttributes(),
519 AttributeSet::ReturnIndex);
518 AttrBuilder CallerAttrs(F->getAttributes(), AttributeList::ReturnIndex);
520519 AttrBuilder CalleeAttrs(cast(I)->getAttributes(),
521 AttributeSet::ReturnIndex);
520 AttributeList::ReturnIndex);
522521
523522 // Noalias is completely benign as far as calling convention goes, it
524523 // shouldn't affect whether the call is a tail call.
15311531
15321532 Type *ResultTy;
15331533 SmallVector Args;
1534 AttributeSet Attr;
1534 AttributeList Attr;
15351535
15361536 // 'size' argument.
15371537 if (!UseSizedLibcall) {
15921592 // Now, the return type.
15931593 if (CASExpected) {
15941594 ResultTy = Type::getInt1Ty(Ctx);
1595 Attr = Attr.addAttribute(Ctx, AttributeSet::ReturnIndex, Attribute::ZExt);
1595 Attr = Attr.addAttribute(Ctx, AttributeList::ReturnIndex, Attribute::ZExt);
15961596 } else if (HasResult && UseSizedLibcall)
15971597 ResultTy = SizedIntTy;
15981598 else
23992399
24002400 // Conservatively require the attributes of the call to match those of the
24012401 // return. Ignore noalias because it doesn't affect the call sequence.
2402 AttributeSet CalleeAttrs = CS.getAttributes();
2403 if (AttrBuilder(CalleeAttrs, AttributeSet::ReturnIndex).
2404 removeAttribute(Attribute::NoAlias) !=
2405 AttrBuilder(CalleeAttrs, AttributeSet::ReturnIndex).
2406 removeAttribute(Attribute::NoAlias))
2402 AttributeList CalleeAttrs = CS.getAttributes();
2403 if (AttrBuilder(CalleeAttrs, AttributeList::ReturnIndex)
2404 .removeAttribute(Attribute::NoAlias) !=
2405 AttrBuilder(CalleeAttrs, AttributeList::ReturnIndex)
2406 .removeAttribute(Attribute::NoAlias))
24072407 continue;
24082408
24092409 // Make sure the call instruction is followed by an unconditional branch to
4949
5050 ArgInfo OrigRet{ResReg, CS.getType(), ISD::ArgFlagsTy{}};
5151 if (!OrigRet.Ty->isVoidTy())
52 setArgFlags(OrigRet, AttributeSet::ReturnIndex, DL, CS);
52 setArgFlags(OrigRet, AttributeList::ReturnIndex, DL, CS);
5353
5454 return lowerCall(MIRBuilder, CS.getCallingConv(), Callee, OrigRet, OrigArgs);
5555 }
5858 void CallLowering::setArgFlags(CallLowering::ArgInfo &Arg, unsigned OpIdx,
5959 const DataLayout &DL,
6060 const FuncInfoTy &FuncInfo) const {
61 const AttributeSet &Attrs = FuncInfo.getAttributes();
61 const AttributeList &Attrs = FuncInfo.getAttributes();
6262 if (Attrs.hasAttribute(OpIdx, Attribute::ZExt))
6363 Arg.Flags.setZExt();
6464 if (Attrs.hasAttribute(OpIdx, Attribute::SExt))
732732 return false;
733733
734734 if (mf.getFunction()->getAttributes().hasAttribute(
735 AttributeSet::FunctionIndex, Attribute::OptimizeForSize) &&
735 AttributeList::FunctionIndex, Attribute::OptimizeForSize) &&
736736 !EnableSWPOptSize.getPosition())
737737 return false;
738738
26162616 // If integer divide is expensive and we satisfy the requirements, emit an
26172617 // alternate sequence. Targets may check function attributes for size/speed
26182618 // trade-offs.
2619 AttributeSet Attr = DAG.getMachineFunction().getFunction()->getAttributes();
2619 AttributeList Attr = DAG.getMachineFunction().getFunction()->getAttributes();
26202620 if (N1C && !TLI.isIntDivCheap(N->getValueType(0), Attr))
26212621 if (SDValue Op = BuildSDIV(N))
26222622 return Op;
26872687 }
26882688
26892689 // fold (udiv x, c) -> alternate
2690 AttributeSet Attr = DAG.getMachineFunction().getFunction()->getAttributes();
2690 AttributeList Attr = DAG.getMachineFunction().getFunction()->getAttributes();
26912691 if (N1C && !TLI.isIntDivCheap(N->getValueType(0), Attr))
26922692 if (SDValue Op = BuildUDIV(N))
26932693 return Op;
27462746 }
27472747 }
27482748
2749 AttributeSet Attr = DAG.getMachineFunction().getFunction()->getAttributes();
2749 AttributeList Attr = DAG.getMachineFunction().getFunction()->getAttributes();
27502750
27512751 // If X/C can be simplified by the division-by-constant logic, lower
27522752 // X%C to the equivalent of X-X/C*C.
862862 return true;
863863 }
864864
865 /// Returns an AttributeSet representing the attributes applied to the return
865 /// Returns an AttributeList representing the attributes applied to the return
866866 /// value of the given call.
867 static AttributeSet getReturnAttrs(FastISel::CallLoweringInfo &CLI) {
867 static AttributeList getReturnAttrs(FastISel::CallLoweringInfo &CLI) {
868868 SmallVector Attrs;
869869 if (CLI.RetSExt)
870870 Attrs.push_back(Attribute::SExt);
873873 if (CLI.IsInReg)
874874 Attrs.push_back(Attribute::InReg);
875875
876 return AttributeSet::get(CLI.RetTy->getContext(), AttributeSet::ReturnIndex,
877 Attrs);
876 return AttributeList::get(CLI.RetTy->getContext(), AttributeList::ReturnIndex,
877 Attrs);
878878 }
879879
880880 bool FastISel::lowerCallTo(const CallInst *CI, const char *SymName,
13721372 const Function *F = I.getParent()->getParent();
13731373
13741374 ISD::NodeType ExtendKind = ISD::ANY_EXTEND;
1375 if (F->getAttributes().hasAttribute(AttributeSet::ReturnIndex,
1375 if (F->getAttributes().hasAttribute(AttributeList::ReturnIndex,
13761376 Attribute::SExt))
13771377 ExtendKind = ISD::SIGN_EXTEND;
1378 else if (F->getAttributes().hasAttribute(AttributeSet::ReturnIndex,
1378 else if (F->getAttributes().hasAttribute(AttributeList::ReturnIndex,
13791379 Attribute::ZExt))
13801380 ExtendKind = ISD::ZERO_EXTEND;
13811381
13821382 LLVMContext &Context = F->getContext();
1383 bool RetInReg = F->getAttributes().hasAttribute(AttributeSet::ReturnIndex,
1384 Attribute::InReg);
1383 bool RetInReg = F->getAttributes().hasAttribute(
1384 AttributeList::ReturnIndex, Attribute::InReg);
13851385
13861386 for (unsigned j = 0; j != NumValues; ++j) {
13871387 EVT VT = ValueVTs[j];
55245524 case Intrinsic::trap: {
55255525 StringRef TrapFuncName =
55265526 I.getAttributes()
5527 .getAttribute(AttributeSet::FunctionIndex, "trap-func-name")
5527 .getAttribute(AttributeList::FunctionIndex, "trap-func-name")
55285528 .getValueAsString();
55295529 if (TrapFuncName.empty()) {
55305530 ISD::NodeType Op = (Intrinsic == Intrinsic::trap) ?
76027602 FuncInfo.MF->getFrameInfo().setHasPatchPoint();
76037603 }
76047604
7605 /// Returns an AttributeSet representing the attributes applied to the return
7605 /// Returns an AttributeList representing the attributes applied to the return
76067606 /// value of the given call.
7607 static AttributeSet getReturnAttrs(TargetLowering::CallLoweringInfo &CLI) {
7607 static AttributeList getReturnAttrs(TargetLowering::CallLoweringInfo &CLI) {
76087608 SmallVector Attrs;
76097609 if (CLI.RetSExt)
76107610 Attrs.push_back(Attribute::SExt);
76137613 if (CLI.IsInReg)
76147614 Attrs.push_back(Attribute::InReg);
76157615
7616 return AttributeSet::get(CLI.RetTy->getContext(), AttributeSet::ReturnIndex,
7617 Attrs);
7616 return AttributeList::get(CLI.RetTy->getContext(), AttributeList::ReturnIndex,
7617 Attrs);
76187618 }
76197619
76207620 /// TargetLowering::LowerCallTo - This is the default LowerCallTo
5454
5555 // Conservatively require the attributes of the call to match those of
5656 // the return. Ignore noalias because it doesn't affect the call sequence.
57 AttributeSet CallerAttrs = F->getAttributes();
58 if (AttrBuilder(CallerAttrs, AttributeSet::ReturnIndex)
59 .removeAttribute(Attribute::NoAlias).hasAttributes())
57 AttributeList CallerAttrs = F->getAttributes();
58 if (AttrBuilder(CallerAttrs, AttributeList::ReturnIndex)
59 .removeAttribute(Attribute::NoAlias)
60 .hasAttributes())
6061 return false;
6162
6263 // It's not safe to eliminate the sign / zero extension of the return value.
63 if (CallerAttrs.hasAttribute(AttributeSet::ReturnIndex, Attribute::ZExt) ||
64 CallerAttrs.hasAttribute(AttributeSet::ReturnIndex, Attribute::SExt))
64 if (CallerAttrs.hasAttribute(AttributeList::ReturnIndex, Attribute::ZExt) ||
65 CallerAttrs.hasAttribute(AttributeList::ReturnIndex, Attribute::SExt))
6566 return false;
6667
6768 // Check if the only use is a function return node.
29802981 SDValue TargetLowering::BuildSDIVPow2(SDNode *N, const APInt &Divisor,
29812982 SelectionDAG &DAG,
29822983 std::vector *Created) const {
2983 AttributeSet Attr = DAG.getMachineFunction().getFunction()->getAttributes();
2984 AttributeList Attr = DAG.getMachineFunction().getFunction()->getAttributes();
29842985 const TargetLowering &TLI = DAG.getTargetLoweringInfo();
29852986 if (TLI.isIntDivCheap(N->getValueType(0), Attr))
29862987 return SDValue(N,0); // Lower SDIV as SDIV
15881588 /// type of the given function. This does not require a DAG or a return value,
15891589 /// and is suitable for use before any DAGs for the function are constructed.
15901590 /// TODO: Move this out of TargetLowering.cpp.
1591 void llvm::GetReturnInfo(Type *ReturnType, AttributeSet attr,
1591 void llvm::GetReturnInfo(Type *ReturnType, AttributeList attr,
15921592 SmallVectorImpl &Outs,
15931593 const TargetLowering &TLI, const DataLayout &DL) {
15941594 SmallVector ValueVTs;
16001600 EVT VT = ValueVTs[j];
16011601 ISD::NodeType ExtendKind = ISD::ANY_EXTEND;
16021602
1603 if (attr.hasAttribute(AttributeSet::ReturnIndex, Attribute::SExt))
1603 if (attr.hasAttribute(AttributeList::ReturnIndex, Attribute::SExt))
16041604 ExtendKind = ISD::SIGN_EXTEND;
1605 else if (attr.hasAttribute(AttributeSet::ReturnIndex, Attribute::ZExt))
1605 else if (attr.hasAttribute(AttributeList::ReturnIndex, Attribute::ZExt))
16061606 ExtendKind = ISD::ZERO_EXTEND;
16071607
16081608 // FIXME: C calling convention requires the return type to be promoted to
16201620
16211621 // 'inreg' on function refers to return value
16221622 ISD::ArgFlagsTy Flags = ISD::ArgFlagsTy();
1623 if (attr.hasAttribute(AttributeSet::ReturnIndex, Attribute::InReg))
1623 if (attr.hasAttribute(AttributeList::ReturnIndex, Attribute::InReg))
16241624 Flags.setInReg();
16251625
16261626 // Propagate extension type if any
1627 if (attr.hasAttribute(AttributeSet::ReturnIndex, Attribute::SExt))
1627 if (attr.hasAttribute(AttributeList::ReturnIndex, Attribute::SExt))
16281628 Flags.setSExt();
1629 else if (attr.hasAttribute(AttributeSet::ReturnIndex, Attribute::ZExt))
1629 else if (attr.hasAttribute(AttributeList::ReturnIndex, Attribute::ZExt))
16301630 Flags.setZExt();
16311631
16321632 for (unsigned i = 0; i < NumParts; ++i)
187187 for (auto &F : *Mod) {
188188 auto Attrs = F.getAttributes();
189189 StringRef Value(options.NoFramePointerElim ? "true" : "false");
190 Attrs = Attrs.addAttribute(F.getContext(), AttributeSet::FunctionIndex,
190 Attrs = Attrs.addAttribute(F.getContext(), AttributeList::FunctionIndex,
191191 "no-frame-pointer-elim", Value);
192192 F.setAttributes(Attrs);
193193 }
603603 unsigned mdnNext;
604604
605605 /// asMap - The slot map for attribute sets.
606 DenseMapSet, unsigned> asMap;
606 DenseMapList, unsigned> asMap;
607607 unsigned asNext;
608608 public:
609609 /// Construct from a module.
626626 int getLocalSlot(const Value *V);
627627 int getGlobalSlot(const GlobalValue *V);
628628 int getMetadataSlot(const MDNode *N);
629 int getAttributeGroupSlot(AttributeSet AS);
629 int getAttributeGroupSlot(AttributeList AS);
630630
631631 /// If you'd like to deal with a function instead of just a module, use
632632 /// this method to get its data into the SlotTracker.
649649 unsigned mdn_size() const { return mdnMap.size(); }
650650 bool mdn_empty() const { return mdnMap.empty(); }
651651
652 /// AttributeSet map iterators.
653 typedef DenseMap::iterator as_iterator;
652 /// AttributeList map iterators.
653 typedef DenseMap::iterator as_iterator;
654654 as_iterator as_begin() { return asMap.begin(); }
655655 as_iterator as_end() { return asMap.end(); }
656656 unsigned as_size() const { return asMap.size(); }
670670 /// CreateFunctionSlot - Insert the specified Value* into the slot table.
671671 void CreateFunctionSlot(const Value *V);
672672
673 /// \brief Insert the specified AttributeSet into the slot table.
674 void CreateAttributeSetSlot(AttributeSet AS);
673 /// \brief Insert the specified AttributeList into the slot table.
674 void CreateAttributeSetSlot(AttributeList AS);
675675
676676 /// Add all of the module level global variables (and their initializers)
677677 /// and function declarations, but not the contents of those functions.
830830
831831 // Add all the function attributes to the table.
832832 // FIXME: Add attributes of other objects?
833 AttributeSet FnAttrs = F.getAttributes().getFnAttributes();
834 if (FnAttrs.hasAttributes(AttributeSet::FunctionIndex))
833 AttributeList FnAttrs = F.getAttributes().getFnAttributes();
834 if (FnAttrs.hasAttributes(AttributeList::FunctionIndex))
835835 CreateAttributeSetSlot(FnAttrs);
836836 }
837837
868868 // target may not be linked into the optimizer.
869869 if (const CallInst *CI = dyn_cast(&I)) {
870870 // Add all the call attributes to the table.
871 AttributeSet Attrs = CI->getAttributes().getFnAttributes();
872 if (Attrs.hasAttributes(AttributeSet::FunctionIndex))
871 AttributeList Attrs = CI->getAttributes().getFnAttributes();
872 if (Attrs.hasAttributes(AttributeList::FunctionIndex))
873873 CreateAttributeSetSlot(Attrs);
874874 } else if (const InvokeInst *II = dyn_cast(&I)) {
875875 // Add all the call attributes to the table.
876 AttributeSet Attrs = II->getAttributes().getFnAttributes();
877 if (Attrs.hasAttributes(AttributeSet::FunctionIndex))
876 AttributeList Attrs = II->getAttributes().getFnAttributes();
877 if (Attrs.hasAttributes(AttributeList::FunctionIndex))
878878 CreateAttributeSetSlot(Attrs);
879879 }
880880 }
960960 return FI == fMap.end() ? -1 : (int)FI->second;
961961 }
962962
963 int SlotTracker::getAttributeGroupSlot(AttributeSet AS) {
963 int SlotTracker::getAttributeGroupSlot(AttributeList AS) {
964964 // Check for uninitialized state and do lazy initialization.
965965 initialize();
966966
967 // Find the AttributeSet in the module map.
967 // Find the AttributeList in the module map.
968968 as_iterator AI = asMap.find(AS);
969969 return AI == asMap.end() ? -1 : (int)AI->second;
970970 }
10141014 CreateMetadataSlot(Op);
10151015 }
10161016
1017 void SlotTracker::CreateAttributeSetSlot(AttributeSet AS) {
1018 assert(AS.hasAttributes(AttributeSet::FunctionIndex) &&
1017 void SlotTracker::CreateAttributeSetSlot(AttributeList AS) {
1018 assert(AS.hasAttributes(AttributeList::FunctionIndex) &&
10191019 "Doesn't need a slot!");
10201020
10211021 as_iterator I = asMap.find(AS);
20872087 void printModule(const Module *M);
20882088
20892089 void writeOperand(const Value *Op, bool PrintType);
2090 void writeParamOperand(const Value *Operand, AttributeSet Attrs,unsigned Idx);
2090 void writeParamOperand(const Value *Operand, AttributeList Attrs,
2091 unsigned Idx);
20912092 void writeOperandBundles(ImmutableCallSite CS);
20922093 void writeAtomic(AtomicOrdering Ordering, SynchronizationScope SynchScope);
20932094 void writeAtomicCmpXchg(AtomicOrdering SuccessOrdering,
21032104 void printIndirectSymbol(const GlobalIndirectSymbol *GIS);
21042105 void printComdat(const Comdat *C);
21052106 void printFunction(const Function *F);
2106 void printArgument(const Argument *FA, AttributeSet Attrs, unsigned Idx);
2107 void printArgument(const Argument *FA, AttributeList Attrs, unsigned Idx);
21072108 void printBasicBlock(const BasicBlock *BB);
21082109 void printInstructionLine(const Instruction &I);
21092110 void printInstruction(const Instruction &I);
21822183 }
21832184
21842185 void AssemblyWriter::writeParamOperand(const Value *Operand,
2185 AttributeSet Attrs, unsigned Idx) {
2186 AttributeList Attrs, unsigned Idx) {
21862187 if (!Operand) {
21872188 Out << "";
21882189 return;
26002601 if (F->isMaterializable())
26012602 Out << "; Materializable\n";
26022603
2603 const AttributeSet &Attrs = F->getAttributes();
2604 if (Attrs.hasAttributes(AttributeSet::FunctionIndex)) {
2605 AttributeSet AS = Attrs.getFnAttributes();
2604 const AttributeList &Attrs = F->getAttributes();
2605 if (Attrs.hasAttributes(AttributeList::FunctionIndex)) {
2606 AttributeList AS = Attrs.getFnAttributes();
26062607 std::string AttrStr;
26072608
26082609 unsigned Idx = 0;
26092610 for (unsigned E = AS.getNumSlots(); Idx != E; ++Idx)
2610 if (AS.getSlotIndex(Idx) == AttributeSet::FunctionIndex)
2611 if (AS.getSlotIndex(Idx) == AttributeList::FunctionIndex)
26112612 break;
26122613
2613 for (AttributeSet::iterator I = AS.begin(Idx), E = AS.end(Idx);
2614 I != E; ++I) {
2614 for (AttributeList::iterator I = AS.begin(Idx), E = AS.end(Idx); I != E;
2615 ++I) {
26152616 Attribute Attr = *I;
26162617 if (!Attr.isStringAttribute()) {
26172618 if (!AttrStr.empty()) AttrStr += ' ';
26452646 }
26462647
26472648 FunctionType *FT = F->getFunctionType();
2648 if (Attrs.hasAttributes(AttributeSet::ReturnIndex))
2649 Out << Attrs.getAsString(AttributeSet::ReturnIndex) << ' ';
2649 if (Attrs.hasAttributes(AttributeList::ReturnIndex))
2650 Out << Attrs.getAsString(AttributeList::ReturnIndex) << ' ';
26502651 TypePrinter.print(F->getReturnType(), Out);
26512652 Out << ' ';
26522653 WriteAsOperandInternal(Out, F, &TypePrinter, &Machine, F->getParent());
26852686 StringRef UA = getUnnamedAddrEncoding(F->getUnnamedAddr());
26862687 if (!UA.empty())
26872688 Out << ' ' << UA;
2688 if (Attrs.hasAttributes(AttributeSet::FunctionIndex))
2689 if (Attrs.hasAttributes(AttributeList::FunctionIndex))
26892690 Out << " #" << Machine.getAttributeGroupSlot(Attrs.getFnAttributes());
26902691 if (F->hasSection()) {
26912692 Out << " section \"";
27342735 /// printArgument - This member is called for every argument that is passed into
27352736 /// the function. Simply print it out
27362737 ///
2737 void AssemblyWriter::printArgument(const Argument *Arg,
2738 AttributeSet Attrs, unsigned Idx) {
2738 void AssemblyWriter::printArgument(const Argument *Arg, AttributeList Attrs,
2739 unsigned Idx) {
27392740 // Output type...
27402741 TypePrinter.print(Arg->getType(), Out);
27412742
30193020 Operand = CI->getCalledValue();
30203021 FunctionType *FTy = CI->getFunctionType();
30213022 Type *RetTy = FTy->getReturnType();
3022 const AttributeSet &PAL = CI->getAttributes();
3023
3024 if (PAL.hasAttributes(AttributeSet::ReturnIndex))
3025 Out << ' ' << PAL.getAsString(AttributeSet::ReturnIndex);
3023 const AttributeList &PAL = CI->getAttributes();
3024
3025 if (PAL.hasAttributes(AttributeList::ReturnIndex))
3026 Out << ' ' << PAL.getAsString(AttributeList::ReturnIndex);
30263027
30273028 // If possible, print out the short form of the call instruction. We can
30283029 // only do this if the first argument is a pointer to a nonvararg function,
30473048 Out << ", ...";
30483049
30493050 Out << ')';
3050 if (PAL.hasAttributes(AttributeSet::FunctionIndex))
3051 if (PAL.hasAttributes(AttributeList::FunctionIndex))
30513052 Out << " #" << Machine.getAttributeGroupSlot(PAL.getFnAttributes());
30523053
30533054 writeOperandBundles(CI);
30563057 Operand = II->getCalledValue();
30573058 FunctionType *FTy = II->getFunctionType();
30583059 Type *RetTy = FTy->getReturnType();
3059 const AttributeSet &PAL = II->getAttributes();
3060 const AttributeList &PAL = II->getAttributes();
30603061
30613062 // Print the calling convention being used.
30623063 if (II->getCallingConv() != CallingConv::C) {
30643065 PrintCallingConv(II->getCallingConv(), Out);
30653066 }
30663067
3067 if (PAL.hasAttributes(AttributeSet::ReturnIndex))
3068 Out << ' ' << PAL.getAsString(AttributeSet::ReturnIndex);
3068 if (PAL.hasAttributes(AttributeList::ReturnIndex))
3069 Out << ' ' << PAL.getAsString(AttributeList::ReturnIndex);
30693070
30703071 // If possible, print out the short form of the invoke instruction. We can
30713072 // only do this if the first argument is a pointer to a nonvararg function,
30833084 }
30843085
30853086 Out << ')';
3086 if (PAL.hasAttributes(AttributeSet::FunctionIndex))
3087 if (PAL.hasAttributes(AttributeList::FunctionIndex))
30873088 Out << " #" << Machine.getAttributeGroupSlot(PAL.getFnAttributes());
30883089
30893090 writeOperandBundles(II);
32463247 }
32473248
32483249 void AssemblyWriter::writeAllAttributeGroups() {
3249 std::vectorSet, unsigned> > asVec;
3250 std::vectorList, unsigned>> asVec;
32503251 asVec.resize(Machine.as_size());
32513252
32523253 for (SlotTracker::as_iterator I = Machine.as_begin(), E = Machine.as_end();
32553256
32563257 for (const auto &I : asVec)
32573258 Out << "attributes #" << I.second << " = { "
3258 << I.first.getAsString(AttributeSet::FunctionIndex, true) << " }\n";
3259 << I.first.getAsString(AttributeList::FunctionIndex, true) << " }\n";
32593260 }
32603261
32613262 void AssemblyWriter::printUseListOrder(const UseListOrder &Order) {
149149 /// \class
150150 /// \brief This class represents a set of attributes that apply to the function,
151151 /// return type, and parameters.
152 class AttributeSetImpl final
152 class AttributeListImpl final
153153 : public FoldingSetNode,
154 private TrailingObjects {
155 friend class AttributeSet;
154 private TrailingObjects {
155 friend class AttributeList;
156156 friend TrailingObjects;
157157
158158 private:
170170 }
171171
172172 public:
173 AttributeSetImpl(LLVMContext &C,
174 ArrayRef> Slots)
173 AttributeListImpl(LLVMContext &C,
174 ArrayRef> Slots)
175175 : Context(C), NumSlots(Slots.size()), AvailableFunctionAttrs(0) {
176176 static_assert(Attribute::EndAttrKinds <=
177177 sizeof(AvailableFunctionAttrs) * CHAR_BIT,
191191
192192 // Initialize AvailableFunctionAttrs summary bitset.
193193 if (NumSlots > 0) {
194 static_assert(AttributeSet::FunctionIndex == ~0u,
194 static_assert(AttributeList::FunctionIndex == ~0u,
195195 "FunctionIndex should be biggest possible index");
196196 const std::pair &Last = Slots.back();
197 if (Last.first == AttributeSet::FunctionIndex) {
197 if (Last.first == AttributeList::FunctionIndex) {
198198 const AttributeSetNode *Node = Last.second;
199199 for (Attribute I : *Node) {
200200 if (!I.isStringAttribute())
205205 }
206206
207207 // AttributesSetImpt is uniqued, these should not be available.
208 AttributeSetImpl(const AttributeSetImpl &) = delete;
209 AttributeSetImpl &operator=(const AttributeSetImpl &) = delete;
208 AttributeListImpl(const AttributeListImpl &) = delete;
209 AttributeListImpl &operator=(const AttributeListImpl &) = delete;
210210
211211 void operator delete(void *p) { ::operator delete(p); }
212212
213 /// \brief Get the context that created this AttributeSetImpl.
213 /// \brief Get the context that created this AttributeListImpl.
214214 LLVMContext &getContext() { return Context; }
215215
216216 /// \brief Return the number of slots used in this attribute list. This is
229229 /// \brief Retrieve the attributes for the given "slot" in the AttrNode list.
230230 /// \p Slot is an index into the AttrNodes list, not the index of the return /
231231 /// parameter/ function which the attributes apply to.
232 AttributeSet getSlotAttributes(unsigned Slot) const {
233 return AttributeSet::get(Context, *getNode(Slot));
232 AttributeList getSlotAttributes(unsigned Slot) const {
233 return AttributeList::get(Context, *getNode(Slot));
234234 }
235235
236236 /// \brief Retrieve the attribute set node for the given "slot" in the
None //===-- AttributeSetNode.h - AttributeSet Internal Node ---------*- C++ -*-===//
0 //===-- AttributeSetNode.h - AttributeList Internal Node ---------*- C++
1 //-*-===//
12 //
23 // The LLVM Compiler Infrastructure
34 //
78 //===----------------------------------------------------------------------===//
89 ///
910 /// \file
10 /// \brief This file defines the node class used internally by AttributeSet.
11 /// \brief This file defines the node class used internally by AttributeList.
1112 ///
1213 //===----------------------------------------------------------------------===//
1314
6465
6566 static AttributeSetNode *get(LLVMContext &C, ArrayRef Attrs);
6667
67 static AttributeSetNode *get(AttributeSet AS, unsigned Index) {
68 static AttributeSetNode *get(AttributeList AS, unsigned Index) {
6869 return AS.getAttributes(Index);
6970 }
7071
71 /// \brief Return the number of attributes this AttributeSet contains.
72 /// \brief Return the number of attributes this AttributeList contains.
7273 unsigned getNumAttributes() const { return NumAttrs; }
7374
7475 bool hasAttribute(Attribute::AttrKind Kind) const {
88 //
99 // \file
1010 // \brief This file implements the Attribute, AttributeImpl, AttrBuilder,
11 // AttributeSetImpl, and AttributeSet classes.
11 // AttributeListImpl, and AttributeList classes.
1212 //
1313 //===----------------------------------------------------------------------===//
1414
522522 pImpl->AttrsSetNodes.InsertNode(PA, InsertPoint);
523523 }
524524
525 // Return the AttributesListNode that we found or created.
525 // Return the AttributeSetNode that we found or created.
526526 return PA;
527527 }
528528
596596 }
597597
598598 //===----------------------------------------------------------------------===//
599 // AttributeSetImpl Definition
599 // AttributeListImpl Definition
600600 //===----------------------------------------------------------------------===//
601601
602602 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
603 LLVM_DUMP_METHOD void AttributeSetImpl::dump() const {
604 AttributeSet(const_cast(this)).dump();
603 LLVM_DUMP_METHOD void AttributeListImpl::dump() const {
604 AttributeList(const_cast(this)).dump();
605605 }
606606 #endif
607607
608608 //===----------------------------------------------------------------------===//
609 // AttributeSet Construction and Mutation Methods
610 //===----------------------------------------------------------------------===//
611
612 AttributeSet
613 AttributeSet::getImpl(LLVMContext &C,
614 ArrayRef> Attrs) {
609 // AttributeList Construction and Mutation Methods
610 //===----------------------------------------------------------------------===//
611
612 AttributeList AttributeList::getImpl(
613 LLVMContext &C, ArrayRef> Attrs) {
615614 LLVMContextImpl *pImpl = C.pImpl;
616615 FoldingSetNodeID ID;
617 AttributeSetImpl::Profile(ID, Attrs);
616 AttributeListImpl::Profile(ID, Attrs);
618617
619618 void *InsertPoint;
620 AttributeSetImpl *PA = pImpl->AttrsLists.FindNodeOrInsertPos(ID, InsertPoint);
619 AttributeListImpl *PA =
620 pImpl->AttrsLists.FindNodeOrInsertPos(ID, InsertPoint);
621621
622622 // If we didn't find any existing attributes of the same shape then
623623 // create a new one and insert it.
624624 if (!PA) {
625 // Coallocate entries after the AttributeSetImpl itself.
625 // Coallocate entries after the AttributeListImpl itself.
626626 void *Mem = ::operator new(
627 AttributeSetImpl::totalSizeToAlloc(Attrs.size()));
628 PA = new (Mem) AttributeSetImpl(C, Attrs);
627 AttributeListImpl::totalSizeToAlloc(Attrs.size()));
628 PA = new (Mem) AttributeListImpl(C, Attrs);
629629 pImpl->AttrsLists.InsertNode(PA, InsertPoint);
630630 }
631631
632632 // Return the AttributesList that we found or created.
633 return AttributeSet(PA);
634 }
635
636 AttributeSet AttributeSet::get(LLVMContext &C,
637 ArrayRef> Attrs) {
633 return AttributeList(PA);
634 }
635
636 AttributeList
637 AttributeList::get(LLVMContext &C,
638 ArrayRef> Attrs) {
638639 // If there are no attributes then return a null AttributesList pointer.
639640 if (Attrs.empty())
640 return AttributeSet();
641 return AttributeList();
641642
642643 assert(std::is_sorted(Attrs.begin(), Attrs.end(),
643644 [](const std::pair &LHS,
668669 return getImpl(C, AttrPairVec);
669670 }
670671
671 AttributeSet AttributeSet::get(LLVMContext &C,
672 ArrayRef
673 AttributeSetNode*>> Attrs) {
672 AttributeList
673 AttributeList::get(LLVMContext &C,
674 ArrayRef> Attrs) {
674675 // If there are no attributes then return a null AttributesList pointer.
675676 if (Attrs.empty())
676 return AttributeSet();
677 return AttributeList();
677678
678679 return getImpl(C, Attrs);
679680 }
680681
681 AttributeSet AttributeSet::get(LLVMContext &C, unsigned Index,
682 const AttrBuilder &B) {
682 AttributeList AttributeList::get(LLVMContext &C, unsigned Index,
683 const AttrBuilder &B) {
683684 if (!B.hasAttributes())
684 return AttributeSet();
685 return AttributeList();
685686
686687 // Add target-independent attributes.
687688 SmallVector, 8> Attrs;
724725 return get(C, Attrs);
725726 }
726727
727 AttributeSet AttributeSet::get(LLVMContext &C, unsigned Index,
728 ArrayRef Kinds) {
728 AttributeList AttributeList::get(LLVMContext &C, unsigned Index,
729 ArrayRef Kinds) {
729730 SmallVector, 8> Attrs;
730731 for (Attribute::AttrKind K : Kinds)
731732 Attrs.emplace_back(Index, Attribute::get(C, K));
732733 return get(C, Attrs);
733734 }
734735
735 AttributeSet AttributeSet::get(LLVMContext &C, unsigned Index,
736 ArrayRef Kinds) {
736 AttributeList AttributeList::get(LLVMContext &C, unsigned Index,
737 ArrayRef Kinds) {
737738 SmallVector, 8> Attrs;
738739 for (StringRef K : Kinds)
739740 Attrs.emplace_back(Index, Attribute::get(C, K));
740741 return get(C, Attrs);
741742 }
742743
743 AttributeSet AttributeSet::get(LLVMContext &C, ArrayRef Attrs) {
744 if (Attrs.empty()) return AttributeSet();
744 AttributeList AttributeList::get(LLVMContext &C,
745 ArrayRef Attrs) {
746 if (Attrs.empty())
747 return AttributeList();
745748 if (Attrs.size() == 1) return Attrs[0];
746749
747750 SmallVector, 8> AttrNodeVec;
748 AttributeSetImpl *A0 = Attrs[0].pImpl;
751 AttributeListImpl *A0 = Attrs[0].pImpl;
749752 if (A0)
750753 AttrNodeVec.append(A0->getNode(0), A0->getNode(A0->getNumSlots()));
751754 // Copy all attributes from Attrs into AttrNodeVec while keeping AttrNodeVec
753756 // index we only need to merge each successive list in rather than doing a
754757 // full sort.
755758 for (unsigned I = 1, E = Attrs.size(); I != E; ++I) {
756 AttributeSetImpl *AS = Attrs[I].pImpl;
759 AttributeListImpl *AS = Attrs[I].pImpl;
757760 if (!AS) continue;
758761 SmallVector, 8>::iterator
759762 ANVI = AttrNodeVec.begin(), ANVE;
770773 return getImpl(C, AttrNodeVec);
771774 }
772775
773 AttributeSet AttributeSet::addAttribute(LLVMContext &C, unsigned Index,
774 Attribute::AttrKind Kind) const {
776 AttributeList AttributeList::addAttribute(LLVMContext &C, unsigned Index,
777 Attribute::AttrKind Kind) const {
775778 if (hasAttribute(Index, Kind)) return *this;
776 return addAttributes(C, Index, AttributeSet::get(C, Index, Kind));
777 }
778
779 AttributeSet AttributeSet::addAttribute(LLVMContext &C, unsigned Index,
780 StringRef Kind, StringRef Value) const {
779 return addAttributes(C, Index, AttributeList::get(C, Index, Kind));
780 }
781
782 AttributeList AttributeList::addAttribute(LLVMContext &C, unsigned Index,
783 StringRef Kind,
784 StringRef Value) const {
781785 AttrBuilder B;
782786 B.addAttribute(Kind, Value);
783 return addAttributes(C, Index, AttributeSet::get(C, Index, B));
784 }
785
786 AttributeSet AttributeSet::addAttribute(LLVMContext &C,
787 ArrayRef Indices,
788 Attribute A) const {
787 return addAttributes(C, Index, AttributeList::get(C, Index, B));
788 }
789
790 AttributeList AttributeList::addAttribute(LLVMContext &C,
791 ArrayRef Indices,
792 Attribute A) const {
789793 unsigned I = 0, E = pImpl ? pImpl->getNumSlots() : 0;
790794 auto IdxI = Indices.begin(), IdxE = Indices.end();
791 SmallVectorSet, 4> AttrSet;
795 SmallVectorList, 4> AttrSet;
792796
793797 while (I != E && IdxI != IdxE) {
794798 if (getSlotIndex(I) < *IdxI)
795799 AttrSet.emplace_back(getSlotAttributes(I++));
796800 else if (getSlotIndex(I) > *IdxI)
797 AttrSet.emplace_back(AttributeSet::get(C, std::make_pair(*IdxI++, A)));
801 AttrSet.emplace_back(AttributeList::get(C, std::make_pair(*IdxI++, A)));
798802 else {
799803 AttrBuilder B(getSlotAttributes(I), *IdxI);
800804 B.addAttribute(A);
801 AttrSet.emplace_back(AttributeSet::get(C, *IdxI, B));
805 AttrSet.emplace_back(AttributeList::get(C, *IdxI, B));
802806 ++I;
803807 ++IdxI;
804808 }
808812 AttrSet.emplace_back(getSlotAttributes(I++));
809813
810814 while (IdxI != IdxE)
811 AttrSet.emplace_back(AttributeSet::get(C, std::make_pair(*IdxI++, A)));
815 AttrSet.emplace_back(AttributeList::get(C, std::make_pair(*IdxI++, A)));
812816
813817 return get(C, AttrSet);
814818 }
815819
816 AttributeSet AttributeSet::addAttributes(LLVMContext &C, unsigned Index,
817 AttributeSet Attrs) const {
820 AttributeList AttributeList::addAttributes(LLVMContext &C, unsigned Index,
821 AttributeList Attrs) const {
818822 if (!pImpl) return Attrs;
819823 if (!Attrs.pImpl) return *this;
820824
828832 #endif
829833
830834 // Add the attribute slots before the one we're trying to add.
831 SmallVectorSet, 4> AttrSet;
835 SmallVectorList, 4> AttrSet;
832836 uint64_t NumAttrs = pImpl->getNumSlots();
833 AttributeSet AS;
837 AttributeList AS;
834838 uint64_t LastIndex = 0;
835839 for (unsigned I = 0, E = NumAttrs; I != E; ++I) {
836840 if (getSlotIndex(I) >= Index) {
842846 }
843847
844848 // Now add the attribute into the correct slot. There may already be an
845 // AttributeSet there.
849 // AttributeList there.
846850 AttrBuilder B(AS, Index);
847851
848852 for (unsigned I = 0, E = Attrs.pImpl->getNumSlots(); I != E; ++I)
849853 if (Attrs.getSlotIndex(I) == Index) {
850 for (AttributeSetImpl::iterator II = Attrs.pImpl->begin(I),
851 IE = Attrs.pImpl->end(I); II != IE; ++II)
854 for (AttributeListImpl::iterator II = Attrs.pImpl->begin(I),
855 IE = Attrs.pImpl->end(I);
856 II != IE; ++II)
852857 B.addAttribute(*II);
853858 break;
854859 }
855860
856 AttrSet.push_back(AttributeSet::get(C, Index, B));
861 AttrSet.push_back(AttributeList::get(C, Index, B));
857862
858863 // Add the remaining attribute slots.
859864 for (unsigned I = LastIndex, E = NumAttrs; I < E; ++I)
862867 return get(C, AttrSet);
863868 }
864869
865 AttributeSet AttributeSet::removeAttribute(LLVMContext &C, unsigned Index,
866 Attribute::AttrKind Kind) const {
870 AttributeList AttributeList::removeAttribute(LLVMContext &C, unsigned Index,
871 Attribute::AttrKind Kind) const {
867872 if (!hasAttribute(Index, Kind)) return *this;
868 return removeAttributes(C, Index, AttributeSet::get(C, Index, Kind));
869 }
870
871 AttributeSet AttributeSet::removeAttribute(LLVMContext &C, unsigned Index,
872 StringRef Kind) const {
873 return removeAttributes(C, Index, AttributeList::get(C, Index, Kind));
874 }
875
876 AttributeList AttributeList::removeAttribute(LLVMContext &C, unsigned Index,
877 StringRef Kind) const {
873878 if (!hasAttribute(Index, Kind)) return *this;
874 return removeAttributes(C, Index, AttributeSet::get(C, Index, Kind));
875 }
876
877 AttributeSet AttributeSet::removeAttributes(LLVMContext &C, unsigned Index,
878 AttributeSet Attrs) const {
879 if (!pImpl) return AttributeSet();
879 return removeAttributes(C, Index, AttributeList::get(C, Index, Kind));
880 }
881
882 AttributeList AttributeList::removeAttributes(LLVMContext &C, unsigned Index,
883 AttributeList Attrs) const {
884 if (!pImpl)
885 return AttributeList();
880886 if (!Attrs.pImpl) return *this;
881887
882888 // FIXME it is not obvious how this should work for alignment.
885891 "Attempt to change alignment!");
886892
887893 // Add the attribute slots before the one we're trying to add.
888 SmallVectorSet, 4> AttrSet;
894 SmallVectorList, 4> AttrSet;
889895 uint64_t NumAttrs = pImpl->getNumSlots();
890 AttributeSet AS;
896 AttributeList AS;
891897 uint64_t LastIndex = 0;
892898 for (unsigned I = 0, E = NumAttrs; I != E; ++I) {
893899 if (getSlotIndex(I) >= Index) {
899905 }
900906
901907 // Now remove the attribute from the correct slot. There may already be an
902 // AttributeSet there.
908 // AttributeList there.
903909 AttrBuilder B(AS, Index);
904910
905911 for (unsigned I = 0, E = Attrs.pImpl->getNumSlots(); I != E; ++I)
908914 break;
909915 }
910916
911 AttrSet.push_back(AttributeSet::get(C, Index, B));
917 AttrSet.push_back(AttributeList::get(C, Index, B));
912918
913919 // Add the remaining attribute slots.
914920 for (unsigned I = LastIndex, E = NumAttrs; I < E; ++I)
917923 return get(C, AttrSet);
918924 }
919925
920 AttributeSet AttributeSet::removeAttributes(LLVMContext &C, unsigned Index,
921 const AttrBuilder &Attrs) const {
922 if (!pImpl) return AttributeSet();
926 AttributeList AttributeList::removeAttributes(LLVMContext &C, unsigned Index,
927 const AttrBuilder &Attrs) const {
928 if (!pImpl)
929 return AttributeList();
923930
924931 // FIXME it is not obvious how this should work for alignment.
925932 // For now, say we can't pass in alignment, which no current use does.
926933 assert(!Attrs.hasAlignmentAttr() && "Attempt to change alignment!");
927934
928935 // Add the attribute slots before the one we're trying to add.
929 SmallVectorSet, 4> AttrSet;
936 SmallVectorList, 4> AttrSet;
930937 uint64_t NumAttrs = pImpl->getNumSlots();
931 AttributeSet AS;
938 AttributeList AS;
932939 uint64_t LastIndex = 0;
933940 for (unsigned I = 0, E = NumAttrs; I != E; ++I) {
934941 if (getSlotIndex(I) >= Index) {
940947 }
941948
942949 // Now remove the attribute from the correct slot. There may already be an
943 // AttributeSet there.
950 // AttributeList there.
944951 AttrBuilder B(AS, Index);
945952 B.remove(Attrs);
946953
947 AttrSet.push_back(AttributeSet::get(C, Index, B));
954 AttrSet.push_back(AttributeList::get(C, Index, B));
948955
949956 // Add the remaining attribute slots.
950957 for (unsigned I = LastIndex, E = NumAttrs; I < E; ++I)
953960 return get(C, AttrSet);
954961 }
955962
956 AttributeSet AttributeSet::addDereferenceableAttr(LLVMContext &C, unsigned Index,
957 uint64_t Bytes) const {
963 AttributeList AttributeList::addDereferenceableAttr(LLVMContext &C,
964 unsigned Index,
965 uint64_t Bytes) const {
958966 AttrBuilder B;
959967 B.addDereferenceableAttr(Bytes);
960 return addAttributes(C, Index, AttributeSet::get(C, Index, B));
961 }
962
963 AttributeSet AttributeSet::addDereferenceableOrNullAttr(LLVMContext &C,
964 unsigned Index,
965 uint64_t Bytes) const {
968 return addAttributes(C, Index, AttributeList::get(C, Index, B));
969 }
970
971 AttributeList
972 AttributeList::addDereferenceableOrNullAttr(LLVMContext &C, unsigned Index,
973 uint64_t Bytes) const {
966974 AttrBuilder B;
967975 B.addDereferenceableOrNullAttr(Bytes);
968 return addAttributes(C, Index, AttributeSet::get(C, Index, B));
969 }
970
971 AttributeSet
972 AttributeSet::addAllocSizeAttr(LLVMContext &C, unsigned Index,
973 unsigned ElemSizeArg,
974 const Optional &NumElemsArg) {
976 return addAttributes(C, Index, AttributeList::get(C, Index, B));
977 }
978
979 AttributeList
980 AttributeList::addAllocSizeAttr(LLVMContext &C, unsigned Index,
981 unsigned ElemSizeArg,
982 const Optional &NumElemsArg) {
975983 AttrBuilder B;
976984 B.addAllocSizeAttr(ElemSizeArg, NumElemsArg);
977 return addAttributes(C, Index, AttributeSet::get(C, Index, B));
978 }
979
980 //===----------------------------------------------------------------------===//
981 // AttributeSet Accessor Methods
982 //===----------------------------------------------------------------------===//
983
984 LLVMContext &AttributeSet::getContext() const {
985 return pImpl->getContext();
986 }
987
988 AttributeSet AttributeSet::getParamAttributes(unsigned Index) const {
989 return pImpl && hasAttributes(Index) ?
990 AttributeSet::get(pImpl->getContext(),
991 ArrayRef>(
992 std::make_pair(Index, getAttributes(Index)))) :
993 AttributeSet();
994 }
995
996 AttributeSet AttributeSet::getRetAttributes() const {
997 return pImpl && hasAttributes(ReturnIndex) ?
998 AttributeSet::get(pImpl->getContext(),
999 ArrayRef>(
1000 std::make_pair(ReturnIndex,
1001 getAttributes(ReturnIndex)))) :
1002 AttributeSet();
1003 }
1004
1005 AttributeSet AttributeSet::getFnAttributes() const {
1006 return pImpl && hasAttributes(FunctionIndex) ?
1007 AttributeSet::get(pImpl->getContext(),
1008 ArrayRef>(
1009 std::make_pair(FunctionIndex,
1010 getAttributes(FunctionIndex)))) :
1011 AttributeSet();
1012 }
1013
1014 bool AttributeSet::hasAttribute(unsigned Index, Attribute::AttrKind Kind) const{
985 return addAttributes(C, Index, AttributeList::get(C, Index, B));
986 }
987
988 //===----------------------------------------------------------------------===//
989 // AttributeList Accessor Methods
990 //===----------------------------------------------------------------------===//
991
992 LLVMContext &AttributeList::getContext() const { return pImpl->getContext(); }
993
994 AttributeList AttributeList::getParamAttributes(unsigned Index) const {
995 return pImpl && hasAttributes(Index)
996 ? AttributeList::get(
997 pImpl->getContext(),
998 ArrayRef>(
999 std::make_pair(Index, getAttributes(Index))))
1000 : AttributeList();
1001 }
1002
1003 AttributeList AttributeList::getRetAttributes() const {
1004 return pImpl && hasAttributes(ReturnIndex)
1005 ? AttributeList::get(
1006 pImpl->getContext(),
1007 ArrayRef>(
1008 std::make_pair(ReturnIndex, getAttributes(ReturnIndex))))
1009 : AttributeList();
1010 }
1011
1012 AttributeList AttributeList::getFnAttributes() const {
1013 return pImpl && hasAttributes(FunctionIndex)
1014 ? AttributeList::get(
1015 pImpl->getContext(),
1016 ArrayRef>(
1017 std::make_pair(FunctionIndex,
1018 getAttributes(FunctionIndex))))
1019 : AttributeList();
1020 }
1021
1022 bool AttributeList::hasAttribute(unsigned Index,
1023 Attribute::AttrKind Kind) const {
10151024 AttributeSetNode *ASN = getAttributes(Index);
10161025 return ASN && ASN->hasAttribute(Kind);
10171026 }
10181027
1019 bool AttributeSet::hasAttribute(unsigned Index, StringRef Kind) const {
1028 bool AttributeList::hasAttribute(unsigned Index, StringRef Kind) const {
10201029 AttributeSetNode *ASN = getAttributes(Index);
10211030 return ASN && ASN->hasAttribute(Kind);
10221031 }
10231032
1024 bool AttributeSet::hasAttributes(unsigned Index) const {
1033 bool AttributeList::hasAttributes(unsigned Index) const {
10251034 AttributeSetNode *ASN = getAttributes(Index);
10261035 return ASN && ASN->hasAttributes();
10271036 }
10281037
1029 bool AttributeSet::hasFnAttribute(Attribute::AttrKind Kind) const {
1038 bool AttributeList::hasFnAttribute(Attribute::AttrKind Kind) const {
10301039 return pImpl && pImpl->hasFnAttribute(Kind);
10311040 }
10321041
1033 bool AttributeSet::hasFnAttribute(StringRef Kind) const {
1034 return hasAttribute(AttributeSet::FunctionIndex, Kind);
1035 }
1036
1037 bool AttributeSet::hasAttrSomewhere(Attribute::AttrKind Attr,
1038 unsigned *Index) const {
1042 bool AttributeList::hasFnAttribute(StringRef Kind) const {
1043 return hasAttribute(AttributeList::FunctionIndex, Kind);
1044 }
1045
1046 bool AttributeList::hasAttrSomewhere(Attribute::AttrKind Attr,
1047 unsigned *Index) const {
10391048 if (!pImpl) return false;
10401049
10411050 for (unsigned I = 0, E = pImpl->getNumSlots(); I != E; ++I)
1042 for (AttributeSetImpl::iterator II = pImpl->begin(I),
1043 IE = pImpl->end(I); II != IE; ++II)
1051 for (AttributeListImpl::iterator II = pImpl->begin(I), IE = pImpl->end(I);
1052 II != IE; ++II)
10441053 if (II->hasAttribute(Attr)) {
10451054 if (Index) *Index = pImpl->getSlotIndex(I);
10461055 return true;
10491058 return false;
10501059 }
10511060
1052 Attribute AttributeSet::getAttribute(unsigned Index,
1053 Attribute::AttrKind Kind) const {
1061 Attribute AttributeList::getAttribute(unsigned Index,
1062 Attribute::AttrKind Kind) const {
10541063 AttributeSetNode *ASN = getAttributes(Index);
10551064 return ASN ? ASN->getAttribute(Kind) : Attribute();
10561065 }
10571066
1058 Attribute AttributeSet::getAttribute(unsigned Index,
1059 StringRef Kind) const {
1067 Attribute AttributeList::getAttribute(unsigned Index, StringRef Kind) const {
10601068 AttributeSetNode *ASN = getAttributes(Index);
10611069 return ASN ? ASN->getAttribute(Kind) : Attribute();
10621070 }
10631071
1064 unsigned AttributeSet::getParamAlignment(unsigned Index) const {
1072 unsigned AttributeList::getParamAlignment(unsigned Index) const {
10651073 AttributeSetNode *ASN = getAttributes(Index);
10661074 return ASN ? ASN->getAlignment() : 0;
10671075 }
10681076
1069 unsigned AttributeSet::getStackAlignment(unsigned Index) const {
1077 unsigned AttributeList::getStackAlignment(unsigned Index) const {
10701078 AttributeSetNode *ASN = getAttributes(Index);
10711079 return ASN ? ASN->getStackAlignment() : 0;
10721080 }
10731081
1074 uint64_t AttributeSet::getDereferenceableBytes(unsigned Index) const {
1082 uint64_t AttributeList::getDereferenceableBytes(unsigned Index) const {
10751083 AttributeSetNode *ASN = getAttributes(Index);
10761084 return ASN ? ASN->getDereferenceableBytes() : 0;
10771085 }
10781086
1079 uint64_t AttributeSet::getDereferenceableOrNullBytes(unsigned Index) const {
1087 uint64_t AttributeList::getDereferenceableOrNullBytes(unsigned Index) const {
10801088 AttributeSetNode *ASN = getAttributes(Index);
10811089 return ASN ? ASN->getDereferenceableOrNullBytes() : 0;
10821090 }
10831091
10841092 std::pair>
1085 AttributeSet::getAllocSizeArgs(unsigned Index) const {
1093 AttributeList::getAllocSizeArgs(unsigned Index) const {
10861094 AttributeSetNode *ASN = getAttributes(Index);
10871095 return ASN ? ASN->getAllocSizeArgs() : std::make_pair(0u, Optional(0u));
10881096 }
10891097
1090 std::string AttributeSet::getAsString(unsigned Index, bool InAttrGrp) const {
1098 std::string AttributeList::getAsString(unsigned Index, bool InAttrGrp) const {
10911099 AttributeSetNode *ASN = getAttributes(Index);
10921100 return ASN ? ASN->getAsString(InAttrGrp) : std::string("");
10931101 }
10941102
1095 AttributeSetNode *AttributeSet::getAttributes(unsigned Index) const {
1103 AttributeSetNode *AttributeList::getAttributes(unsigned Index) const {
10961104 if (!pImpl) return nullptr;
10971105
10981106 // Loop through to find the attribute node we want.
11031111 return nullptr;
11041112 }
11051113
1106 AttributeSet::iterator AttributeSet::begin(unsigned Slot) const {
1114 AttributeList::iterator AttributeList::begin(unsigned Slot) const {
11071115 if (!pImpl)
11081116 return ArrayRef().begin();
11091117 return pImpl->begin(Slot);
11101118 }
11111119
1112 AttributeSet::iterator AttributeSet::end(unsigned Slot) const {
1120 AttributeList::iterator AttributeList::end(unsigned Slot) const {
11131121 if (!pImpl)
11141122 return ArrayRef().end();
11151123 return pImpl->end(Slot);
11161124 }
11171125
11181126 //===----------------------------------------------------------------------===//
1119 // AttributeSet Introspection Methods
1120 //===----------------------------------------------------------------------===//
1121
1122 unsigned AttributeSet::getNumSlots() const {
1127 // AttributeList Introspection Methods
1128 //===----------------------------------------------------------------------===//
1129
1130 unsigned AttributeList::getNumSlots() const {
11231131 return pImpl ? pImpl->getNumSlots() : 0;
11241132 }
11251133
1126 unsigned AttributeSet::getSlotIndex(unsigned Slot) const {
1134 unsigned AttributeList::getSlotIndex(unsigned Slot) const {
11271135 assert(pImpl && Slot < pImpl->getNumSlots() &&
11281136 "Slot # out of range!");
11291137 return pImpl->getSlotIndex(Slot);
11301138 }
11311139
1132 AttributeSet AttributeSet::getSlotAttributes(unsigned Slot) const {
1140 AttributeList AttributeList::getSlotAttributes(unsigned Slot) const {
11331141 assert(pImpl && Slot < pImpl->getNumSlots() &&
11341142 "Slot # out of range!");
11351143 return pImpl->getSlotAttributes(Slot);
11361144 }
11371145
11381146 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1139 LLVM_DUMP_METHOD void AttributeSet::dump() const {
1147 LLVM_DUMP_METHOD void AttributeList::dump() const {
11401148 dbgs() << "PAL[\n";
11411149
11421150 for (unsigned i = 0, e = getNumSlots(); i < e; ++i) {
11571165 // AttrBuilder Method Implementations
11581166 //===----------------------------------------------------------------------===//
11591167
1160 AttrBuilder::AttrBuilder(AttributeSet AS, unsigned Index) {
1161 AttributeSetImpl *pImpl = AS.pImpl;
1168 AttrBuilder::AttrBuilder(AttributeList AS, unsigned Index) {
1169 AttributeListImpl *pImpl = AS.pImpl;
11621170 if (!pImpl) return;
11631171
11641172 for (unsigned I = 0, E = pImpl->getNumSlots(); I != E; ++I) {
11651173 if (pImpl->getSlotIndex(I) != Index) continue;
11661174
1167 for (AttributeSetImpl::iterator II = pImpl->begin(I),
1168 IE = pImpl->end(I); II != IE; ++II)
1175 for (AttributeListImpl::iterator II = pImpl->begin(I), IE = pImpl->end(I);
1176 II != IE; ++II)
11691177 addAttribute(*II);
11701178
11711179 break;
12331241 return *this;
12341242 }
12351243
1236 AttrBuilder &AttrBuilder::removeAttributes(AttributeSet A, uint64_t Index) {
1244 AttrBuilder &AttrBuilder::removeAttributes(AttributeList A, uint64_t Index) {
12371245 unsigned Slot = ~0U;
12381246 for (unsigned I = 0, E = A.getNumSlots(); I != E; ++I)
12391247 if (A.getSlotIndex(I) == Index) {
12411249 break;
12421250 }
12431251
1244 assert(Slot != ~0U && "Couldn't find index in AttributeSet!");
1245
1246 for (AttributeSet::iterator I = A.begin(Slot), E = A.end(Slot); I != E; ++I) {
1252 assert(Slot != ~0U && "Couldn't find index in AttributeList!");
1253
1254 for (AttributeList::iterator I = A.begin(Slot), E = A.end(Slot); I != E;
1255 ++I) {
12471256 Attribute Attr = *I;
12481257 if (Attr.isEnumAttribute() || Attr.isIntAttribute()) {
12491258 removeAttribute(Attr.getKindAsEnum());
13941403 return !Attrs.none() || !TargetDepAttrs.empty();
13951404 }
13961405
1397 bool AttrBuilder::hasAttributes(AttributeSet A, uint64_t Index) const {
1406 bool AttrBuilder::hasAttributes(AttributeList A, uint64_t Index) const {
13981407 unsigned Slot = ~0U;
13991408 for (unsigned I = 0, E = A.getNumSlots(); I != E; ++I)
14001409 if (A.getSlotIndex(I) == Index) {
14041413
14051414 assert(Slot != ~0U && "Couldn't find the index!");
14061415
1407 for (AttributeSet::iterator I = A.begin(Slot), E = A.end(Slot); I != E; ++I) {
1416 for (AttributeList::iterator I = A.begin(Slot), E = A.end(Slot); I != E;
1417 ++I) {
14081418 Attribute Attr = *I;
14091419 if (Attr.isEnumAttribute() || Attr.isIntAttribute()) {
14101420 if (Attrs[I->getKindAsEnum()])
15051515 B.addAttribute(Attribute::StackProtect)
15061516 .addAttribute(Attribute::StackProtectStrong)
15071517 .addAttribute(Attribute::StackProtectReq);
1508 AttributeSet OldSSPAttr = AttributeSet::get(Caller.getContext(),
1509 AttributeSet::FunctionIndex,
1510 B);
1518 AttributeList OldSSPAttr =
1519 AttributeList::get(Caller.getContext(), AttributeList::FunctionIndex, B);
15111520
15121521 if (Callee.hasFnAttribute(Attribute::StackProtectReq)) {
1513 Caller.removeAttributes(AttributeSet::FunctionIndex, OldSSPAttr);
1522 Caller.removeAttributes(AttributeList::FunctionIndex, OldSSPAttr);
15141523 Caller.addFnAttr(Attribute::StackProtectReq);
15151524 } else if (Callee.hasFnAttribute(Attribute::StackProtectStrong) &&
15161525 !Caller.hasFnAttribute(Attribute::StackProtectReq)) {
1517 Caller.removeAttributes(AttributeSet::FunctionIndex, OldSSPAttr);
1526 Caller.removeAttributes(AttributeList::FunctionIndex, OldSSPAttr);
15181527 Caller.addFnAttr(Attribute::StackProtectStrong);
15191528 } else if (Callee.hasFnAttribute(Attribute::StackProtect) &&
15201529 !Caller.hasFnAttribute(Attribute::StackProtectReq) &&
18871887 void LLVMAddTargetDependentFunctionAttr(LLVMValueRef Fn, const char *A,
18881888 const char *V) {
18891889 Function *Func = unwrap(Fn);
1890 AttributeSet::AttrIndex Idx =
1891 AttributeSet::AttrIndex(AttributeSet::FunctionIndex);
1890 AttributeList::AttrIndex Idx =
1891 AttributeList::AttrIndex(AttributeList::FunctionIndex);
18921892 AttrBuilder B;
18931893
18941894 B.addAttribute(A, V);
1895 AttributeSet Set = AttributeSet::get(Func->getContext(), Idx, B);
1895 AttributeList Set = AttributeList::get(Func->getContext(), Idx, B);
18961896 Func->addAttributes(Idx, Set);
18971897 }
18981898
19551955 Argument *A = unwrap(Arg);
19561956 AttrBuilder B;
19571957 B.addAlignmentAttr(align);
1958 A->addAttr(AttributeSet::get(A->getContext(),A->getArgNo() + 1, B));
1958 A->addAttr(AttributeList::get(A->getContext(), A->getArgNo() + 1, B));
19591959 }
19601960
19611961 /*--.. Operations on basic blocks ..........................................--*/
21642164 CallSite Call = CallSite(unwrap(Instr));
21652165 AttrBuilder B;
21662166 B.addAlignmentAttr(align);
2167 Call.setAttributes(Call.getAttributes()
2168 .addAttributes(Call->getContext(), index,
2169 AttributeSet::get(Call->getContext(),
2170 index, B)));
2167 Call.setAttributes(Call.getAttributes().addAttributes(
2168 Call->getContext(), index,
2169 AttributeList::get(Call->getContext(), index, B)));
21712170 }
21722171
21732172 void LLVMAddCallSiteAttribute(LLVMValueRef C, LLVMAttributeIndex Idx,
7979
8080 bool Argument::hasByValOrInAllocaAttr() const {
8181 if (!getType()->isPointerTy()) return false;
82 AttributeSet Attrs = getParent()->getAttributes();
82 AttributeList Attrs = getParent()->getAttributes();
8383 return Attrs.hasAttribute(getArgNo() + 1, Attribute::ByVal) ||
8484 Attrs.hasAttribute(getArgNo() + 1, Attribute::InAlloca);
8585 }
141141 hasAttribute(getArgNo()+1, Attribute::ReadNone);
142142 }
143143
144 void Argument::addAttr(AttributeSet AS) {
144 void Argument::addAttr(AttributeList AS) {
145145 assert(AS.getNumSlots() <= 1 &&
146146 "Trying to add more than one attribute set to an argument!");
147147 AttrBuilder B(AS, AS.getSlotIndex(0));
148 getParent()->addAttributes(getArgNo() + 1,
149 AttributeSet::get(Parent->getContext(),
150 getArgNo() + 1, B));
151 }
152
153 void Argument::removeAttr(AttributeSet AS) {
148 getParent()->addAttributes(
149 getArgNo() + 1,
150 AttributeList::get(Parent->getContext(), getArgNo() + 1, B));
151 }
152
153 void Argument::removeAttr(AttributeList AS) {
154154 assert(AS.getNumSlots() <= 1 &&
155155 "Trying to remove more than one attribute set from an argument!");
156156 AttrBuilder B(AS, AS.getSlotIndex(0));
157 getParent()->removeAttributes(getArgNo() + 1,
158 AttributeSet::get(Parent->getContext(),
159 getArgNo() + 1, B));
157 getParent()->removeAttributes(
158 getArgNo() + 1,
159 AttributeList::get(Parent->getContext(), getArgNo() + 1, B));
160160 }
161161
162162 bool Argument::hasAttribute(Attribute::AttrKind Kind) const {
321321 }
322322
323323 void Function::addAttribute(unsigned i, Attribute::AttrKind Kind) {
324 AttributeSet PAL = getAttributes();
324 AttributeList PAL = getAttributes();
325325 PAL = PAL.addAttribute(getContext(), i, Kind);
326326 setAttributes(PAL);
327327 }
328328
329329 void Function::addAttribute(unsigned i, Attribute Attr) {
330 AttributeSet PAL = getAttributes();
330 AttributeList PAL = getAttributes();
331331 PAL = PAL.addAttribute(getContext(), i, Attr);
332332 setAttributes(PAL);
333333 }
334334
335 void Function::addAttributes(unsigned i, AttributeSet Attrs) {
336 AttributeSet PAL = getAttributes();
335 void Function::addAttributes(unsigned i, AttributeList Attrs) {
336 AttributeList PAL = getAttributes();
337337 PAL = PAL.addAttributes(getContext(), i, Attrs);
338338 setAttributes(PAL);
339339 }
340340
341341 void Function::removeAttribute(unsigned i, Attribute::AttrKind Kind) {
342 AttributeSet PAL = getAttributes();
342 AttributeList PAL = getAttributes();
343343 PAL = PAL.removeAttribute(getContext(), i, Kind);
344344 setAttributes(PAL);
345345 }
346346
347347 void Function::removeAttribute(unsigned i, StringRef Kind) {
348 AttributeSet PAL = getAttributes();
348 AttributeList PAL = getAttributes();
349349 PAL = PAL.removeAttribute(getContext(), i, Kind);
350350 setAttributes(PAL);
351351 }
352352
353 void Function::removeAttributes(unsigned i, AttributeSet Attrs) {
354 AttributeSet PAL = getAttributes();
353 void Function::removeAttributes(unsigned i, AttributeList Attrs) {
354 AttributeList PAL = getAttributes();
355355 PAL = PAL.removeAttributes(getContext(), i, Attrs);
356356 setAttributes(PAL);
357357 }
358358
359359 void Function::addDereferenceableAttr(unsigned i, uint64_t Bytes) {
360 AttributeSet PAL = getAttributes();
360 AttributeList PAL = getAttributes();
361361 PAL = PAL.addDereferenceableAttr(getContext(), i, Bytes);
362362 setAttributes(PAL);
363363 }
364364
365365 void Function::addDereferenceableOrNullAttr(unsigned i, uint64_t Bytes) {
366 AttributeSet PAL = getAttributes();
366 AttributeList PAL = getAttributes();
367367 PAL = PAL.addDereferenceableOrNullAttr(getContext(), i, Bytes);
368368 setAttributes(PAL);
369369 }
306306 : Instruction(CI.getType(), Instruction::Call,
307307 OperandTraits::op_end(this) - CI.getNumOperands(),
308308 CI.getNumOperands()),
309 AttributeList(CI.AttributeList), FTy(CI.FTy) {
309 Attrs(CI.Attrs), FTy(CI.FTy) {
310310 setTailCallKind(CI.getTailCallKind());
311311 setCallingConv(CI.getCallingConv());
312312
333333 Value *CallInst::getReturnedArgOperand() const {
334334 unsigned Index;
335335
336 if (AttributeList.hasAttrSomewhere(Attribute::Returned, &Index) && Index)
336 if (Attrs.hasAttrSomewhere(Attribute::Returned, &Index) && Index)
337337 return getArgOperand(Index-1);
338338 if (const Function *F = getCalledFunction())
339339 if (F->getAttributes().hasAttrSomewhere(Attribute::Returned, &Index) &&
344344 }
345345
346346 void CallInst::addAttribute(unsigned i, Attribute::AttrKind Kind) {
347 AttributeSet PAL = getAttributes();
347 AttributeList PAL = getAttributes();
348348 PAL = PAL.addAttribute(getContext(), i, Kind);
349349 setAttributes(PAL);
350350 }
351351
352352 void CallInst::addAttribute(unsigned i, Attribute Attr) {
353 AttributeSet PAL = getAttributes();
353 AttributeList PAL = getAttributes();
354354 PAL = PAL.addAttribute(getContext(), i, Attr);
355355 setAttributes(PAL);
356356 }
357357
358358 void CallInst::removeAttribute(unsigned i, Attribute::AttrKind Kind) {
359 AttributeSet PAL = getAttributes();
359 AttributeList PAL = getAttributes();
360360 PAL = PAL.removeAttribute(getContext(), i, Kind);
361361 setAttributes(PAL);
362362 }
363363
364364 void CallInst::removeAttribute(unsigned i, StringRef Kind) {
365 AttributeSet PAL = getAttributes();
365 AttributeList PAL = getAttributes();
366366 PAL = PAL.removeAttribute(getContext(), i, Kind);
367367 setAttributes(PAL);
368368 }
369369
370370 void CallInst::addDereferenceableAttr(unsigned i, uint64_t Bytes) {
371 AttributeSet PAL = getAttributes();
371 AttributeList PAL = getAttributes();
372372 PAL = PAL.addDereferenceableAttr(getContext(), i, Bytes);
373373 setAttributes(PAL);
374374 }
375375
376376 void CallInst::addDereferenceableOrNullAttr(unsigned i, uint64_t Bytes) {
377 AttributeSet PAL = getAttributes();
377 AttributeList PAL = getAttributes();
378378 PAL = PAL.addDereferenceableOrNullAttr(getContext(), i, Bytes);
379379 setAttributes(PAL);
380380 }
382382 bool CallInst::paramHasAttr(unsigned i, Attribute::AttrKind Kind) const {
383383 assert(i < (getNumArgOperands() + 1) && "Param index out of bounds!");
384384
385 if (AttributeList.hasAttribute(i, Kind))
385 if (Attrs.hasAttribute(i, Kind))
386386 return true;
387387 if (const Function *F = getCalledFunction())
388388 return F->getAttributes().hasAttribute(i, Kind);
645645 OperandTraits::op_end(this) -
646646 II.getNumOperands(),
647647 II.getNumOperands()),
648 AttributeList(II.AttributeList), FTy(II.FTy) {
648 Attrs(II.Attrs), FTy(II.FTy) {
649649 setCallingConv(II.getCallingConv());
650650 std::copy(II.op_begin(), II.op_end(), op_begin());
651651 std::copy(II.bundle_op_info_begin(), II.bundle_op_info_end(),
680680 Value *InvokeInst::getReturnedArgOperand() const {
681681 unsigned Index;
682682
683 if (AttributeList.hasAttrSomewhere(Attribute::Returned, &Index) && Index)
683 if (Attrs.hasAttrSomewhere(Attribute::Returned, &Index) && Index)
684684 return getArgOperand(Index-1);
685685 if (const Function *F = getCalledFunction())
686686 if (F->getAttributes().hasAttrSomewhere(Attribute::Returned, &Index) &&
693693 bool InvokeInst::paramHasAttr(unsigned i, Attribute::AttrKind Kind) const {
694694 assert(i < (getNumArgOperands() + 1) && "Param index out of bounds!");
695695
696 if (AttributeList.hasAttribute(i, Kind))
696 if (Attrs.hasAttribute(i, Kind))
697697 return true;
698698 if (const Function *F = getCalledFunction())
699699 return F->getAttributes().hasAttribute(i, Kind);
719719 }
720720
721721 void InvokeInst::addAttribute(unsigned i, Attribute::AttrKind Kind) {
722 AttributeSet PAL = getAttributes();
722 AttributeList PAL = getAttributes();
723723 PAL = PAL.addAttribute(getContext(), i, Kind);
724724 setAttributes(PAL);
725725 }
726726
727727 void InvokeInst::addAttribute(unsigned i, Attribute Attr) {
728 AttributeSet PAL = getAttributes();
728 AttributeList PAL = getAttributes();
729729 PAL = PAL.addAttribute(getContext(), i, Attr);
730730 setAttributes(PAL);
731731 }
732732
733733 void InvokeInst::removeAttribute(unsigned i, Attribute::AttrKind Kind) {
734 AttributeSet PAL = getAttributes();
734 AttributeList PAL = getAttributes();
735735 PAL = PAL.removeAttribute(getContext(), i, Kind);
736736 setAttributes(PAL);
737737 }
738738
739739 void InvokeInst::removeAttribute(unsigned i, StringRef Kind) {
740 AttributeSet PAL = getAttributes();
740 AttributeList PAL = getAttributes();
741741 PAL = PAL.removeAttribute(getContext(), i, Kind);
742742 setAttributes(PAL);
743743 }
744744
745745 void InvokeInst::addDereferenceableAttr(unsigned i, uint64_t Bytes) {
746 AttributeSet PAL = getAttributes();
746 AttributeList PAL = getAttributes();
747747 PAL = PAL.addDereferenceableAttr(getContext(), i, Bytes);
748748 setAttributes(PAL);
749749 }
750750
751751 void InvokeInst::addDereferenceableOrNullAttr(unsigned i, uint64_t Bytes) {
752 AttributeSet PAL = getAttributes();
752 AttributeList PAL = getAttributes();
753753 PAL = PAL.addDereferenceableOrNullAttr(getContext(), i, Bytes);
754754 setAttributes(PAL);
755755 }
113113 }
114114
115115 // Destroy attribute lists.
116 for (FoldingSetIterator I = AttrsLists.begin(),
117 E = AttrsLists.end(); I != E; ) {
118 FoldingSetIterator Elem = I++;
116 for (FoldingSetIterator I = AttrsLists.begin(),
117 E = AttrsLists.end();
118 I != E;) {
119 FoldingSetIterator Elem = I++;
119120 delete &*Elem;
120121 }
121122
11181118 FPMapTy FPConstants;
11191119
11201120 FoldingSet AttrsSet;
1121 FoldingSetSetImpl> AttrsLists;
1121 FoldingSetListImpl> AttrsLists;
11221122 FoldingSet AttrsSetNodes;
11231123
11241124 StringMap MDStringCache;
119119 // it. This is nice because it allows most passes to get away with not handling
120120 // the symbol table directly for this common task.
121121 //
122 Constant *Module::getOrInsertFunction(StringRef Name,
123 FunctionType *Ty,
124 AttributeSet AttributeList) {
122 Constant *Module::getOrInsertFunction(StringRef Name, FunctionType *Ty,
123 AttributeList AttributeList) {
125124 // See if we have a definition for the specified function already.
126125 GlobalValue *F = getNamedValue(Name);
127126 if (!F) {
144143
145144 Constant *Module::getOrInsertFunction(StringRef Name,
146145 FunctionType *Ty) {
147 return getOrInsertFunction(Name, Ty, AttributeSet());
146 return getOrInsertFunction(Name, Ty, AttributeList());
148147 }
149148
150149 // getOrInsertFunction - Look up the specified function in the module symbol
153152 // arguments, which makes it easier for clients to use.
154153 //
155154 Constant *Module::getOrInsertFunction(StringRef Name,
156 AttributeSet AttributeList,
157 Type *RetTy, ...) {
155 AttributeList AttributeList, Type *RetTy,
156 ...) {
158157 va_list Args;
159158 va_start(Args, RetTy);
160159
184183 va_end(Args);
185184
186185 // Build the function type and chain to the other getOrInsertFunction...
187 return getOrInsertFunction(Name,
188 FunctionType::get(RetTy, ArgTys, false),
189 AttributeSet());
186 return getOrInsertFunction(Name, FunctionType::get(RetTy, ArgTys, false),
187 AttributeList());
190188 }
191189
192190 // getFunction - Look up the specified function in the module symbol table.
5252 Attr.hasAttribute("statepoint-num-patch-bytes");
5353 }
5454
55 StatepointDirectives llvm::parseStatepointDirectivesFromAttrs(AttributeSet AS) {
55 StatepointDirectives
56 llvm::parseStatepointDirectivesFromAttrs(AttributeList AS) {
5657 StatepointDirectives Result;
5758
5859 Attribute AttrID =
59 AS.getAttribute(AttributeSet::FunctionIndex, "statepoint-id");
60 AS.getAttribute(AttributeList::FunctionIndex, "statepoint-id");
6061 uint64_t StatepointID;
6162 if (AttrID.isStringAttribute())
6263 if (!AttrID.getValueAsString().getAsInteger(10, StatepointID))
6364 Result.StatepointID = StatepointID;
6465
6566 uint32_t NumPatchBytes;
66 Attribute AttrNumPatchBytes = AS.getAttribute(AttributeSet::FunctionIndex,
67 Attribute AttrNumPatchBytes = AS.getAttribute(AttributeList::FunctionIndex,
6768 "statepoint-num-patch-bytes");
6869 if (AttrNumPatchBytes.isStringAttribute())
6970 if (!AttrNumPatchBytes.getValueAsString().getAsInteger(10, NumPatchBytes))
632632 Align = DL.getPrefTypeAlignment(AllocatedType);
633633 }
634634 } else if (auto CS = ImmutableCallSite(this))
635 Align = CS.getAttributes().getParamAlignment(AttributeSet::ReturnIndex);
635 Align = CS.getAttributes().getParamAlignment(AttributeList::ReturnIndex);
636636 else if (const LoadInst *LI = dyn_cast(this))
637637 if (MDNode *MD = LI->getMetadata(LLVMContext::MD_align)) {
638638 ConstantInt *CI = mdconst::extract(MD->getOperand(0));
488488 void verifyMustTailCall(CallInst &CI);
489489 bool performTypeCheck(Intrinsic::ID ID, Function *F, Type *Ty, int VT,
490490 unsigned ArgNo, std::string &Suffix);
491 bool verifyAttributeCount(AttributeSet Attrs, unsigned Params);
492 void verifyAttributeTypes(AttributeSet Attrs, unsigned Idx, bool isFunction,
491 bool verifyAttributeCount(AttributeList Attrs, unsigned Params);
492 void verifyAttributeTypes(AttributeList Attrs, unsigned Idx, bool isFunction,
493493 const Value *V);
494 void verifyParameterAttrs(AttributeSet Attrs, unsigned Idx, Type *Ty,
494 void verifyParameterAttrs(AttributeList Attrs, unsigned Idx, Type *Ty,
495495