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