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