80-column and whitespace fixups.
[oota-llvm.git] / lib / VMCore / Attributes.cpp
1 //===-- Attributes.cpp - Implement AttributesList -------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the Attributes, AttributeImpl, AttrBuilder,
11 // AttributeListImpl, and AttrListPtr classes.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #include "llvm/Attributes.h"
16 #include "AttributesImpl.h"
17 #include "LLVMContextImpl.h"
18 #include "llvm/Type.h"
19 #include "llvm/ADT/StringExtras.h"
20 #include "llvm/ADT/FoldingSet.h"
21 #include "llvm/Support/Atomic.h"
22 #include "llvm/Support/Mutex.h"
23 #include "llvm/Support/Debug.h"
24 #include "llvm/Support/ManagedStatic.h"
25 #include "llvm/Support/raw_ostream.h"
26 using namespace llvm;
27
28 //===----------------------------------------------------------------------===//
29 // Attributes Implementation
30 //===----------------------------------------------------------------------===//
31
32 Attributes Attributes::get(LLVMContext &Context, ArrayRef<AttrVal> Vals) {
33   AttrBuilder B;
34   for (ArrayRef<AttrVal>::iterator I = Vals.begin(), E = Vals.end();
35        I != E; ++I)
36     B.addAttribute(*I);
37   return Attributes::get(Context, B);
38 }
39
40 Attributes Attributes::get(LLVMContext &Context, AttrBuilder &B) {
41   // If there are no attributes, return an empty Attributes class.
42   if (!B.hasAttributes())
43     return Attributes();
44
45   // Otherwise, build a key to look up the existing attributes.
46   LLVMContextImpl *pImpl = Context.pImpl;
47   FoldingSetNodeID ID;
48   ID.AddInteger(B.Raw());
49
50   void *InsertPoint;
51   AttributesImpl *PA = pImpl->AttrsSet.FindNodeOrInsertPos(ID, InsertPoint);
52
53   if (!PA) {
54     // If we didn't find any existing attributes of the same shape then create a
55     // new one and insert it.
56     PA = new AttributesImpl(B.Raw());
57     pImpl->AttrsSet.InsertNode(PA, InsertPoint);
58   }
59
60   // Return the AttributesList that we found or created.
61   return Attributes(PA);
62 }
63
64 bool Attributes::hasAttribute(AttrVal Val) const {
65   return Attrs && Attrs->hasAttribute(Val);
66 }
67
68 bool Attributes::hasAttributes() const {
69   return Attrs && Attrs->hasAttributes();
70 }
71
72 bool Attributes::hasAttributes(const Attributes &A) const {
73   return Attrs && Attrs->hasAttributes(A);
74 }
75
76 /// This returns the alignment field of an attribute as a byte alignment value.
77 unsigned Attributes::getAlignment() const {
78   if (!hasAttribute(Attributes::Alignment))
79     return 0;
80   return 1U << ((Attrs->getAlignment() >> 16) - 1);
81 }
82
83 /// This returns the stack alignment field of an attribute as a byte alignment
84 /// value.
85 unsigned Attributes::getStackAlignment() const {
86   if (!hasAttribute(Attributes::StackAlignment))
87     return 0;
88   return 1U << ((Attrs->getStackAlignment() >> 26) - 1);
89 }
90
91 uint64_t Attributes::Raw() const {
92   return Attrs ? Attrs->Raw() : 0;
93 }
94
95 Attributes Attributes::typeIncompatible(Type *Ty) {
96   AttrBuilder Incompatible;
97
98   if (!Ty->isIntegerTy())
99     // Attributes that only apply to integers.
100     Incompatible.addAttribute(Attributes::SExt)
101       .addAttribute(Attributes::ZExt);
102
103   if (!Ty->isPointerTy())
104     // Attributes that only apply to pointers.
105     Incompatible.addAttribute(Attributes::ByVal)
106       .addAttribute(Attributes::Nest)
107       .addAttribute(Attributes::NoAlias)
108       .addAttribute(Attributes::NoCapture)
109       .addAttribute(Attributes::StructRet);
110
111   return Attributes::get(Ty->getContext(), Incompatible);
112 }
113
114 /// encodeLLVMAttributesForBitcode - This returns an integer containing an
115 /// encoding of all the LLVM attributes found in the given attribute bitset.
116 /// Any change to this encoding is a breaking change to bitcode compatibility.
117 uint64_t Attributes::encodeLLVMAttributesForBitcode(Attributes Attrs) {
118   // FIXME: It doesn't make sense to store the alignment information as an
119   // expanded out value, we should store it as a log2 value.  However, we can't
120   // just change that here without breaking bitcode compatibility.  If this ever
121   // becomes a problem in practice, we should introduce new tag numbers in the
122   // bitcode file and have those tags use a more efficiently encoded alignment
123   // field.
124
125   // Store the alignment in the bitcode as a 16-bit raw value instead of a 5-bit
126   // log2 encoded value. Shift the bits above the alignment up by 11 bits.
127   uint64_t EncodedAttrs = Attrs.Raw() & 0xffff;
128   if (Attrs.hasAttribute(Attributes::Alignment))
129     EncodedAttrs |= Attrs.getAlignment() << 16;
130   EncodedAttrs |= (Attrs.Raw() & (0xffffULL << 21)) << 11;
131   return EncodedAttrs;
132 }
133
134 /// decodeLLVMAttributesForBitcode - This returns an attribute bitset containing
135 /// the LLVM attributes that have been decoded from the given integer.  This
136 /// function must stay in sync with 'encodeLLVMAttributesForBitcode'.
137 Attributes Attributes::decodeLLVMAttributesForBitcode(LLVMContext &C,
138                                                       uint64_t EncodedAttrs) {
139   // The alignment is stored as a 16-bit raw value from bits 31--16.  We shift
140   // the bits above 31 down by 11 bits.
141   unsigned Alignment = (EncodedAttrs & (0xffffULL << 16)) >> 16;
142   assert((!Alignment || isPowerOf2_32(Alignment)) &&
143          "Alignment must be a power of two.");
144
145   AttrBuilder B(EncodedAttrs & 0xffff);
146   if (Alignment)
147     B.addAlignmentAttr(Alignment);
148   B.addRawValue((EncodedAttrs & (0xffffULL << 32)) >> 11);
149   return Attributes::get(C, B);
150 }
151
152 std::string Attributes::getAsString() const {
153   std::string Result;
154   if (hasAttribute(Attributes::ZExt))
155     Result += "zeroext ";
156   if (hasAttribute(Attributes::SExt))
157     Result += "signext ";
158   if (hasAttribute(Attributes::NoReturn))
159     Result += "noreturn ";
160   if (hasAttribute(Attributes::NoUnwind))
161     Result += "nounwind ";
162   if (hasAttribute(Attributes::UWTable))
163     Result += "uwtable ";
164   if (hasAttribute(Attributes::ReturnsTwice))
165     Result += "returns_twice ";
166   if (hasAttribute(Attributes::InReg))
167     Result += "inreg ";
168   if (hasAttribute(Attributes::NoAlias))
169     Result += "noalias ";
170   if (hasAttribute(Attributes::NoCapture))
171     Result += "nocapture ";
172   if (hasAttribute(Attributes::StructRet))
173     Result += "sret ";
174   if (hasAttribute(Attributes::ByVal))
175     Result += "byval ";
176   if (hasAttribute(Attributes::Nest))
177     Result += "nest ";
178   if (hasAttribute(Attributes::ReadNone))
179     Result += "readnone ";
180   if (hasAttribute(Attributes::ReadOnly))
181     Result += "readonly ";
182   if (hasAttribute(Attributes::OptimizeForSize))
183     Result += "optsize ";
184   if (hasAttribute(Attributes::NoInline))
185     Result += "noinline ";
186   if (hasAttribute(Attributes::InlineHint))
187     Result += "inlinehint ";
188   if (hasAttribute(Attributes::AlwaysInline))
189     Result += "alwaysinline ";
190   if (hasAttribute(Attributes::StackProtect))
191     Result += "ssp ";
192   if (hasAttribute(Attributes::StackProtectReq))
193     Result += "sspreq ";
194   if (hasAttribute(Attributes::NoRedZone))
195     Result += "noredzone ";
196   if (hasAttribute(Attributes::NoImplicitFloat))
197     Result += "noimplicitfloat ";
198   if (hasAttribute(Attributes::Naked))
199     Result += "naked ";
200   if (hasAttribute(Attributes::NonLazyBind))
201     Result += "nonlazybind ";
202   if (hasAttribute(Attributes::AddressSafety))
203     Result += "address_safety ";
204   if (hasAttribute(Attributes::MinSize))
205     Result += "minsize ";
206   if (hasAttribute(Attributes::StackAlignment)) {
207     Result += "alignstack(";
208     Result += utostr(getStackAlignment());
209     Result += ") ";
210   }
211   if (hasAttribute(Attributes::Alignment)) {
212     Result += "align ";
213     Result += utostr(getAlignment());
214     Result += " ";
215   }
216   // Trim the trailing space.
217   assert(!Result.empty() && "Unknown attribute!");
218   Result.erase(Result.end()-1);
219   return Result;
220 }
221
222 //===----------------------------------------------------------------------===//
223 // AttrBuilder Implementation
224 //===----------------------------------------------------------------------===//
225
226 AttrBuilder &AttrBuilder::addAttribute(Attributes::AttrVal Val){
227   Bits |= AttributesImpl::getAttrMask(Val);
228   return *this;
229 }
230
231 AttrBuilder &AttrBuilder::addRawValue(uint64_t Val) {
232   Bits |= Val;
233   return *this;
234 }
235
236 AttrBuilder &AttrBuilder::addAlignmentAttr(unsigned Align) {
237   if (Align == 0) return *this;
238   assert(isPowerOf2_32(Align) && "Alignment must be a power of two.");
239   assert(Align <= 0x40000000 && "Alignment too large.");
240   Bits |= (Log2_32(Align) + 1) << 16;
241   return *this;
242 }
243 AttrBuilder &AttrBuilder::addStackAlignmentAttr(unsigned Align){
244   // Default alignment, allow the target to define how to align it.
245   if (Align == 0) return *this;
246   assert(isPowerOf2_32(Align) && "Alignment must be a power of two.");
247   assert(Align <= 0x100 && "Alignment too large.");
248   Bits |= (Log2_32(Align) + 1) << 26;
249   return *this;
250 }
251
252 AttrBuilder &AttrBuilder::removeAttribute(Attributes::AttrVal Val) {
253   Bits &= ~AttributesImpl::getAttrMask(Val);
254   return *this;
255 }
256
257 AttrBuilder &AttrBuilder::addAttributes(const Attributes &A) {
258   Bits |= A.Raw();
259   return *this;
260 }
261
262 AttrBuilder &AttrBuilder::removeAttributes(const Attributes &A){
263   Bits &= ~A.Raw();
264   return *this;
265 }
266
267 bool AttrBuilder::hasAttribute(Attributes::AttrVal A) const {
268   return Bits & AttributesImpl::getAttrMask(A);
269 }
270
271 bool AttrBuilder::hasAttributes() const {
272   return Bits != 0;
273 }
274 bool AttrBuilder::hasAttributes(const Attributes &A) const {
275   return Bits & A.Raw();
276 }
277 bool AttrBuilder::hasAlignmentAttr() const {
278   return Bits & AttributesImpl::getAttrMask(Attributes::Alignment);
279 }
280
281 uint64_t AttrBuilder::getAlignment() const {
282   if (!hasAlignmentAttr())
283     return 0;
284   return 1ULL <<
285     (((Bits & AttributesImpl::getAttrMask(Attributes::Alignment)) >> 16) - 1);
286 }
287
288 uint64_t AttrBuilder::getStackAlignment() const {
289   if (!hasAlignmentAttr())
290     return 0;
291   return 1ULL <<
292     (((Bits & AttributesImpl::getAttrMask(Attributes::StackAlignment))>>26)-1);
293 }
294
295 //===----------------------------------------------------------------------===//
296 // AttributeImpl Definition
297 //===----------------------------------------------------------------------===//
298
299 uint64_t AttributesImpl::getAttrMask(uint64_t Val) {
300   switch (Val) {
301   case Attributes::None:            return 0;
302   case Attributes::ZExt:            return 1 << 0;
303   case Attributes::SExt:            return 1 << 1;
304   case Attributes::NoReturn:        return 1 << 2;
305   case Attributes::InReg:           return 1 << 3;
306   case Attributes::StructRet:       return 1 << 4;
307   case Attributes::NoUnwind:        return 1 << 5;
308   case Attributes::NoAlias:         return 1 << 6;
309   case Attributes::ByVal:           return 1 << 7;
310   case Attributes::Nest:            return 1 << 8;
311   case Attributes::ReadNone:        return 1 << 9;
312   case Attributes::ReadOnly:        return 1 << 10;
313   case Attributes::NoInline:        return 1 << 11;
314   case Attributes::AlwaysInline:    return 1 << 12;
315   case Attributes::OptimizeForSize: return 1 << 13;
316   case Attributes::StackProtect:    return 1 << 14;
317   case Attributes::StackProtectReq: return 1 << 15;
318   case Attributes::Alignment:       return 31 << 16;
319   case Attributes::NoCapture:       return 1 << 21;
320   case Attributes::NoRedZone:       return 1 << 22;
321   case Attributes::NoImplicitFloat: return 1 << 23;
322   case Attributes::Naked:           return 1 << 24;
323   case Attributes::InlineHint:      return 1 << 25;
324   case Attributes::StackAlignment:  return 7 << 26;
325   case Attributes::ReturnsTwice:    return 1 << 29;
326   case Attributes::UWTable:         return 1 << 30;
327   case Attributes::NonLazyBind:     return 1U << 31;
328   case Attributes::AddressSafety:   return 1ULL << 32;
329   case Attributes::MinSize:         return 1ULL << 33;
330   }
331   llvm_unreachable("Unsupported attribute type");
332 }
333
334 bool AttributesImpl::hasAttribute(uint64_t A) const {
335   return (Bits & getAttrMask(A)) != 0;
336 }
337
338 bool AttributesImpl::hasAttributes() const {
339   return Bits != 0;
340 }
341
342 bool AttributesImpl::hasAttributes(const Attributes &A) const {
343   return Bits & A.Raw();        // FIXME: Raw() won't work here in the future.
344 }
345
346 uint64_t AttributesImpl::getAlignment() const {
347   return Bits & getAttrMask(Attributes::Alignment);
348 }
349
350 uint64_t AttributesImpl::getStackAlignment() const {
351   return Bits & getAttrMask(Attributes::StackAlignment);
352 }
353
354 //===----------------------------------------------------------------------===//
355 // AttributeListImpl Definition
356 //===----------------------------------------------------------------------===//
357
358 namespace llvm {
359   class AttributeListImpl;
360 }
361
362 static ManagedStatic<FoldingSet<AttributeListImpl> > AttributesLists;
363
364 namespace llvm {
365 static ManagedStatic<sys::SmartMutex<true> > ALMutex;
366
367 class AttributeListImpl : public FoldingSetNode {
368   sys::cas_flag RefCount;
369
370   // AttributesList is uniqued, these should not be publicly available.
371   void operator=(const AttributeListImpl &) LLVM_DELETED_FUNCTION;
372   AttributeListImpl(const AttributeListImpl &) LLVM_DELETED_FUNCTION;
373   ~AttributeListImpl();                        // Private implementation
374 public:
375   SmallVector<AttributeWithIndex, 4> Attrs;
376
377   AttributeListImpl(ArrayRef<AttributeWithIndex> attrs)
378     : Attrs(attrs.begin(), attrs.end()) {
379     RefCount = 0;
380   }
381
382   void AddRef() {
383     sys::SmartScopedLock<true> Lock(*ALMutex);
384     ++RefCount;
385   }
386   void DropRef() {
387     sys::SmartScopedLock<true> Lock(*ALMutex);
388     if (!AttributesLists.isConstructed())
389       return;
390     sys::cas_flag new_val = --RefCount;
391     if (new_val == 0)
392       delete this;
393   }
394
395   void Profile(FoldingSetNodeID &ID) const {
396     Profile(ID, Attrs);
397   }
398   static void Profile(FoldingSetNodeID &ID, ArrayRef<AttributeWithIndex> Attrs){
399     for (unsigned i = 0, e = Attrs.size(); i != e; ++i) {
400       ID.AddInteger(Attrs[i].Attrs.Raw());
401       ID.AddInteger(Attrs[i].Index);
402     }
403   }
404 };
405
406 } // end llvm namespace
407
408 AttributeListImpl::~AttributeListImpl() {
409   // NOTE: Lock must be acquired by caller.
410   AttributesLists->RemoveNode(this);
411 }
412
413 AttrListPtr AttrListPtr::get(ArrayRef<AttributeWithIndex> Attrs) {
414   // If there are no attributes then return a null AttributesList pointer.
415   if (Attrs.empty())
416     return AttrListPtr();
417
418 #ifndef NDEBUG
419   for (unsigned i = 0, e = Attrs.size(); i != e; ++i) {
420     assert(Attrs[i].Attrs.hasAttributes() &&
421            "Pointless attribute!");
422     assert((!i || Attrs[i-1].Index < Attrs[i].Index) &&
423            "Misordered AttributesList!");
424   }
425 #endif
426
427   // Otherwise, build a key to look up the existing attributes.
428   FoldingSetNodeID ID;
429   AttributeListImpl::Profile(ID, Attrs);
430   void *InsertPos;
431
432   sys::SmartScopedLock<true> Lock(*ALMutex);
433
434   AttributeListImpl *PAL =
435     AttributesLists->FindNodeOrInsertPos(ID, InsertPos);
436
437   // If we didn't find any existing attributes of the same shape then
438   // create a new one and insert it.
439   if (!PAL) {
440     PAL = new AttributeListImpl(Attrs);
441     AttributesLists->InsertNode(PAL, InsertPos);
442   }
443
444   // Return the AttributesList that we found or created.
445   return AttrListPtr(PAL);
446 }
447
448 //===----------------------------------------------------------------------===//
449 // AttrListPtr Method Implementations
450 //===----------------------------------------------------------------------===//
451
452 AttrListPtr::AttrListPtr(AttributeListImpl *LI) : AttrList(LI) {
453   if (LI) LI->AddRef();
454 }
455
456 AttrListPtr::AttrListPtr(const AttrListPtr &P) : AttrList(P.AttrList) {
457   if (AttrList) AttrList->AddRef();
458 }
459
460 const AttrListPtr &AttrListPtr::operator=(const AttrListPtr &RHS) {
461   sys::SmartScopedLock<true> Lock(*ALMutex);
462   if (AttrList == RHS.AttrList) return *this;
463   if (AttrList) AttrList->DropRef();
464   AttrList = RHS.AttrList;
465   if (AttrList) AttrList->AddRef();
466   return *this;
467 }
468
469 AttrListPtr::~AttrListPtr() {
470   if (AttrList) AttrList->DropRef();
471 }
472
473 /// getNumSlots - Return the number of slots used in this attribute list.
474 /// This is the number of arguments that have an attribute set on them
475 /// (including the function itself).
476 unsigned AttrListPtr::getNumSlots() const {
477   return AttrList ? AttrList->Attrs.size() : 0;
478 }
479
480 /// getSlot - Return the AttributeWithIndex at the specified slot.  This
481 /// holds a number plus a set of attributes.
482 const AttributeWithIndex &AttrListPtr::getSlot(unsigned Slot) const {
483   assert(AttrList && Slot < AttrList->Attrs.size() && "Slot # out of range!");
484   return AttrList->Attrs[Slot];
485 }
486
487 /// getAttributes - The attributes for the specified index are returned.
488 /// Attributes for the result are denoted with Idx = 0.  Function notes are
489 /// denoted with idx = ~0.
490 Attributes AttrListPtr::getAttributes(unsigned Idx) const {
491   if (AttrList == 0) return Attributes();
492
493   const SmallVector<AttributeWithIndex, 4> &Attrs = AttrList->Attrs;
494   for (unsigned i = 0, e = Attrs.size(); i != e && Attrs[i].Index <= Idx; ++i)
495     if (Attrs[i].Index == Idx)
496       return Attrs[i].Attrs;
497
498   return Attributes();
499 }
500
501 /// hasAttrSomewhere - Return true if the specified attribute is set for at
502 /// least one parameter or for the return value.
503 bool AttrListPtr::hasAttrSomewhere(Attributes::AttrVal Attr) const {
504   if (AttrList == 0) return false;
505
506   const SmallVector<AttributeWithIndex, 4> &Attrs = AttrList->Attrs;
507   for (unsigned i = 0, e = Attrs.size(); i != e; ++i)
508     if (Attrs[i].Attrs.hasAttribute(Attr))
509       return true;
510   return false;
511 }
512
513 unsigned AttrListPtr::getNumAttrs() const {
514   return AttrList ? AttrList->Attrs.size() : 0;
515 }
516
517 Attributes &AttrListPtr::getAttributesAtIndex(unsigned i) const {
518   assert(AttrList && "Trying to get an attribute from an empty list!");
519   assert(i < AttrList->Attrs.size() && "Index out of range!");
520   return AttrList->Attrs[i].Attrs;
521 }
522
523 AttrListPtr AttrListPtr::addAttr(LLVMContext &C, unsigned Idx,
524                                  Attributes Attrs) const {
525   Attributes OldAttrs = getAttributes(Idx);
526 #ifndef NDEBUG
527   // FIXME it is not obvious how this should work for alignment.
528   // For now, say we can't change a known alignment.
529   unsigned OldAlign = OldAttrs.getAlignment();
530   unsigned NewAlign = Attrs.getAlignment();
531   assert((!OldAlign || !NewAlign || OldAlign == NewAlign) &&
532          "Attempt to change alignment!");
533 #endif
534
535   AttrBuilder NewAttrs =
536     AttrBuilder(OldAttrs).addAttributes(Attrs);
537   if (NewAttrs == AttrBuilder(OldAttrs))
538     return *this;
539
540   SmallVector<AttributeWithIndex, 8> NewAttrList;
541   if (AttrList == 0)
542     NewAttrList.push_back(AttributeWithIndex::get(Idx, Attrs));
543   else {
544     const SmallVector<AttributeWithIndex, 4> &OldAttrList = AttrList->Attrs;
545     unsigned i = 0, e = OldAttrList.size();
546     // Copy attributes for arguments before this one.
547     for (; i != e && OldAttrList[i].Index < Idx; ++i)
548       NewAttrList.push_back(OldAttrList[i]);
549
550     // If there are attributes already at this index, merge them in.
551     if (i != e && OldAttrList[i].Index == Idx) {
552       Attrs =
553         Attributes::get(C, AttrBuilder(Attrs).
554                         addAttributes(OldAttrList[i].Attrs));
555       ++i;
556     }
557
558     NewAttrList.push_back(AttributeWithIndex::get(Idx, Attrs));
559
560     // Copy attributes for arguments after this one.
561     NewAttrList.insert(NewAttrList.end(),
562                        OldAttrList.begin()+i, OldAttrList.end());
563   }
564
565   return get(NewAttrList);
566 }
567
568 AttrListPtr AttrListPtr::removeAttr(LLVMContext &C, unsigned Idx,
569                                     Attributes Attrs) const {
570 #ifndef NDEBUG
571   // FIXME it is not obvious how this should work for alignment.
572   // For now, say we can't pass in alignment, which no current use does.
573   assert(!Attrs.hasAttribute(Attributes::Alignment) &&
574          "Attempt to exclude alignment!");
575 #endif
576   if (AttrList == 0) return AttrListPtr();
577
578   Attributes OldAttrs = getAttributes(Idx);
579   AttrBuilder NewAttrs =
580     AttrBuilder(OldAttrs).removeAttributes(Attrs);
581   if (NewAttrs == AttrBuilder(OldAttrs))
582     return *this;
583
584   SmallVector<AttributeWithIndex, 8> NewAttrList;
585   const SmallVector<AttributeWithIndex, 4> &OldAttrList = AttrList->Attrs;
586   unsigned i = 0, e = OldAttrList.size();
587
588   // Copy attributes for arguments before this one.
589   for (; i != e && OldAttrList[i].Index < Idx; ++i)
590     NewAttrList.push_back(OldAttrList[i]);
591
592   // If there are attributes already at this index, merge them in.
593   assert(OldAttrList[i].Index == Idx && "Attribute isn't set?");
594   Attrs = Attributes::get(C, AttrBuilder(OldAttrList[i].Attrs).
595                           removeAttributes(Attrs));
596   ++i;
597   if (Attrs.hasAttributes()) // If any attributes left for this param, add them.
598     NewAttrList.push_back(AttributeWithIndex::get(Idx, Attrs));
599
600   // Copy attributes for arguments after this one.
601   NewAttrList.insert(NewAttrList.end(),
602                      OldAttrList.begin()+i, OldAttrList.end());
603
604   return get(NewAttrList);
605 }
606
607 void AttrListPtr::dump() const {
608   dbgs() << "PAL[ ";
609   for (unsigned i = 0; i < getNumSlots(); ++i) {
610     const AttributeWithIndex &PAWI = getSlot(i);
611     dbgs() << "{" << PAWI.Index << "," << PAWI.Attrs.getAsString() << "} ";
612   }
613
614   dbgs() << "]\n";
615 }