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