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