LLVM API Documentation

Attributes.cpp
Go to the documentation of this file.
00001 //===-- Attributes.cpp - Implement AttributesList -------------------------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // \file
00011 // \brief This file implements the Attribute, AttributeImpl, AttrBuilder,
00012 // AttributeSetImpl, and AttributeSet classes.
00013 //
00014 //===----------------------------------------------------------------------===//
00015 
00016 #include "llvm/IR/Attributes.h"
00017 #include "AttributeImpl.h"
00018 #include "LLVMContextImpl.h"
00019 #include "llvm/ADT/STLExtras.h"
00020 #include "llvm/ADT/StringExtras.h"
00021 #include "llvm/IR/Type.h"
00022 #include "llvm/Support/Atomic.h"
00023 #include "llvm/Support/Debug.h"
00024 #include "llvm/Support/ManagedStatic.h"
00025 #include "llvm/Support/Mutex.h"
00026 #include "llvm/Support/raw_ostream.h"
00027 #include <algorithm>
00028 using namespace llvm;
00029 
00030 //===----------------------------------------------------------------------===//
00031 // Attribute Construction Methods
00032 //===----------------------------------------------------------------------===//
00033 
00034 Attribute Attribute::get(LLVMContext &Context, Attribute::AttrKind Kind,
00035                          uint64_t Val) {
00036   LLVMContextImpl *pImpl = Context.pImpl;
00037   FoldingSetNodeID ID;
00038   ID.AddInteger(Kind);
00039   if (Val) ID.AddInteger(Val);
00040 
00041   void *InsertPoint;
00042   AttributeImpl *PA = pImpl->AttrsSet.FindNodeOrInsertPos(ID, InsertPoint);
00043 
00044   if (!PA) {
00045     // If we didn't find any existing attributes of the same shape then create a
00046     // new one and insert it.
00047     if (!Val)
00048       PA = new EnumAttributeImpl(Kind);
00049     else
00050       PA = new AlignAttributeImpl(Kind, Val);
00051     pImpl->AttrsSet.InsertNode(PA, InsertPoint);
00052   }
00053 
00054   // Return the Attribute that we found or created.
00055   return Attribute(PA);
00056 }
00057 
00058 Attribute Attribute::get(LLVMContext &Context, StringRef Kind, StringRef Val) {
00059   LLVMContextImpl *pImpl = Context.pImpl;
00060   FoldingSetNodeID ID;
00061   ID.AddString(Kind);
00062   if (!Val.empty()) ID.AddString(Val);
00063 
00064   void *InsertPoint;
00065   AttributeImpl *PA = pImpl->AttrsSet.FindNodeOrInsertPos(ID, InsertPoint);
00066 
00067   if (!PA) {
00068     // If we didn't find any existing attributes of the same shape then create a
00069     // new one and insert it.
00070     PA = new StringAttributeImpl(Kind, Val);
00071     pImpl->AttrsSet.InsertNode(PA, InsertPoint);
00072   }
00073 
00074   // Return the Attribute that we found or created.
00075   return Attribute(PA);
00076 }
00077 
00078 Attribute Attribute::getWithAlignment(LLVMContext &Context, uint64_t Align) {
00079   assert(isPowerOf2_32(Align) && "Alignment must be a power of two.");
00080   assert(Align <= 0x40000000 && "Alignment too large.");
00081   return get(Context, Alignment, Align);
00082 }
00083 
00084 Attribute Attribute::getWithStackAlignment(LLVMContext &Context,
00085                                            uint64_t Align) {
00086   assert(isPowerOf2_32(Align) && "Alignment must be a power of two.");
00087   assert(Align <= 0x100 && "Alignment too large.");
00088   return get(Context, StackAlignment, Align);
00089 }
00090 
00091 //===----------------------------------------------------------------------===//
00092 // Attribute Accessor Methods
00093 //===----------------------------------------------------------------------===//
00094 
00095 bool Attribute::isEnumAttribute() const {
00096   return pImpl && pImpl->isEnumAttribute();
00097 }
00098 
00099 bool Attribute::isAlignAttribute() const {
00100   return pImpl && pImpl->isAlignAttribute();
00101 }
00102 
00103 bool Attribute::isStringAttribute() const {
00104   return pImpl && pImpl->isStringAttribute();
00105 }
00106 
00107 Attribute::AttrKind Attribute::getKindAsEnum() const {
00108   if (!pImpl) return None;
00109   assert((isEnumAttribute() || isAlignAttribute()) &&
00110          "Invalid attribute type to get the kind as an enum!");
00111   return pImpl ? pImpl->getKindAsEnum() : None;
00112 }
00113 
00114 uint64_t Attribute::getValueAsInt() const {
00115   if (!pImpl) return 0;
00116   assert(isAlignAttribute() &&
00117          "Expected the attribute to be an alignment attribute!");
00118   return pImpl ? pImpl->getValueAsInt() : 0;
00119 }
00120 
00121 StringRef Attribute::getKindAsString() const {
00122   if (!pImpl) return StringRef();
00123   assert(isStringAttribute() &&
00124          "Invalid attribute type to get the kind as a string!");
00125   return pImpl ? pImpl->getKindAsString() : StringRef();
00126 }
00127 
00128 StringRef Attribute::getValueAsString() const {
00129   if (!pImpl) return StringRef();
00130   assert(isStringAttribute() &&
00131          "Invalid attribute type to get the value as a string!");
00132   return pImpl ? pImpl->getValueAsString() : StringRef();
00133 }
00134 
00135 bool Attribute::hasAttribute(AttrKind Kind) const {
00136   return (pImpl && pImpl->hasAttribute(Kind)) || (!pImpl && Kind == None);
00137 }
00138 
00139 bool Attribute::hasAttribute(StringRef Kind) const {
00140   if (!isStringAttribute()) return false;
00141   return pImpl && pImpl->hasAttribute(Kind);
00142 }
00143 
00144 /// This returns the alignment field of an attribute as a byte alignment value.
00145 unsigned Attribute::getAlignment() const {
00146   assert(hasAttribute(Attribute::Alignment) &&
00147          "Trying to get alignment from non-alignment attribute!");
00148   return pImpl->getValueAsInt();
00149 }
00150 
00151 /// This returns the stack alignment field of an attribute as a byte alignment
00152 /// value.
00153 unsigned Attribute::getStackAlignment() const {
00154   assert(hasAttribute(Attribute::StackAlignment) &&
00155          "Trying to get alignment from non-alignment attribute!");
00156   return pImpl->getValueAsInt();
00157 }
00158 
00159 std::string Attribute::getAsString(bool InAttrGrp) const {
00160   if (!pImpl) return "";
00161 
00162   if (hasAttribute(Attribute::SanitizeAddress))
00163     return "sanitize_address";
00164   if (hasAttribute(Attribute::AlwaysInline))
00165     return "alwaysinline";
00166   if (hasAttribute(Attribute::Builtin))
00167     return "builtin";
00168   if (hasAttribute(Attribute::ByVal))
00169     return "byval";
00170   if (hasAttribute(Attribute::InAlloca))
00171     return "inalloca";
00172   if (hasAttribute(Attribute::InlineHint))
00173     return "inlinehint";
00174   if (hasAttribute(Attribute::InReg))
00175     return "inreg";
00176   if (hasAttribute(Attribute::MinSize))
00177     return "minsize";
00178   if (hasAttribute(Attribute::Naked))
00179     return "naked";
00180   if (hasAttribute(Attribute::Nest))
00181     return "nest";
00182   if (hasAttribute(Attribute::NoAlias))
00183     return "noalias";
00184   if (hasAttribute(Attribute::NoBuiltin))
00185     return "nobuiltin";
00186   if (hasAttribute(Attribute::NoCapture))
00187     return "nocapture";
00188   if (hasAttribute(Attribute::NoDuplicate))
00189     return "noduplicate";
00190   if (hasAttribute(Attribute::NoImplicitFloat))
00191     return "noimplicitfloat";
00192   if (hasAttribute(Attribute::NoInline))
00193     return "noinline";
00194   if (hasAttribute(Attribute::NonLazyBind))
00195     return "nonlazybind";
00196   if (hasAttribute(Attribute::NoRedZone))
00197     return "noredzone";
00198   if (hasAttribute(Attribute::NoReturn))
00199     return "noreturn";
00200   if (hasAttribute(Attribute::NoUnwind))
00201     return "nounwind";
00202   if (hasAttribute(Attribute::OptimizeNone))
00203     return "optnone";
00204   if (hasAttribute(Attribute::OptimizeForSize))
00205     return "optsize";
00206   if (hasAttribute(Attribute::ReadNone))
00207     return "readnone";
00208   if (hasAttribute(Attribute::ReadOnly))
00209     return "readonly";
00210   if (hasAttribute(Attribute::Returned))
00211     return "returned";
00212   if (hasAttribute(Attribute::ReturnsTwice))
00213     return "returns_twice";
00214   if (hasAttribute(Attribute::SExt))
00215     return "signext";
00216   if (hasAttribute(Attribute::StackProtect))
00217     return "ssp";
00218   if (hasAttribute(Attribute::StackProtectReq))
00219     return "sspreq";
00220   if (hasAttribute(Attribute::StackProtectStrong))
00221     return "sspstrong";
00222   if (hasAttribute(Attribute::StructRet))
00223     return "sret";
00224   if (hasAttribute(Attribute::SanitizeThread))
00225     return "sanitize_thread";
00226   if (hasAttribute(Attribute::SanitizeMemory))
00227     return "sanitize_memory";
00228   if (hasAttribute(Attribute::UWTable))
00229     return "uwtable";
00230   if (hasAttribute(Attribute::ZExt))
00231     return "zeroext";
00232   if (hasAttribute(Attribute::Cold))
00233     return "cold";
00234 
00235   // FIXME: These should be output like this:
00236   //
00237   //   align=4
00238   //   alignstack=8
00239   //
00240   if (hasAttribute(Attribute::Alignment)) {
00241     std::string Result;
00242     Result += "align";
00243     Result += (InAttrGrp) ? "=" : " ";
00244     Result += utostr(getValueAsInt());
00245     return Result;
00246   }
00247 
00248   if (hasAttribute(Attribute::StackAlignment)) {
00249     std::string Result;
00250     Result += "alignstack";
00251     if (InAttrGrp) {
00252       Result += "=";
00253       Result += utostr(getValueAsInt());
00254     } else {
00255       Result += "(";
00256       Result += utostr(getValueAsInt());
00257       Result += ")";
00258     }
00259     return Result;
00260   }
00261 
00262   // Convert target-dependent attributes to strings of the form:
00263   //
00264   //   "kind"
00265   //   "kind" = "value"
00266   //
00267   if (isStringAttribute()) {
00268     std::string Result;
00269     Result += '\"' + getKindAsString().str() + '"';
00270 
00271     StringRef Val = pImpl->getValueAsString();
00272     if (Val.empty()) return Result;
00273 
00274     Result += "=\"" + Val.str() + '"';
00275     return Result;
00276   }
00277 
00278   llvm_unreachable("Unknown attribute");
00279 }
00280 
00281 bool Attribute::operator<(Attribute A) const {
00282   if (!pImpl && !A.pImpl) return false;
00283   if (!pImpl) return true;
00284   if (!A.pImpl) return false;
00285   return *pImpl < *A.pImpl;
00286 }
00287 
00288 //===----------------------------------------------------------------------===//
00289 // AttributeImpl Definition
00290 //===----------------------------------------------------------------------===//
00291 
00292 // Pin the vtabels to this file.
00293 AttributeImpl::~AttributeImpl() {}
00294 void EnumAttributeImpl::anchor() {}
00295 void AlignAttributeImpl::anchor() {}
00296 void StringAttributeImpl::anchor() {}
00297 
00298 bool AttributeImpl::hasAttribute(Attribute::AttrKind A) const {
00299   if (isStringAttribute()) return false;
00300   return getKindAsEnum() == A;
00301 }
00302 
00303 bool AttributeImpl::hasAttribute(StringRef Kind) const {
00304   if (!isStringAttribute()) return false;
00305   return getKindAsString() == Kind;
00306 }
00307 
00308 Attribute::AttrKind AttributeImpl::getKindAsEnum() const {
00309   assert(isEnumAttribute() || isAlignAttribute());
00310   return static_cast<const EnumAttributeImpl *>(this)->getEnumKind();
00311 }
00312 
00313 uint64_t AttributeImpl::getValueAsInt() const {
00314   assert(isAlignAttribute());
00315   return static_cast<const AlignAttributeImpl *>(this)->getAlignment();
00316 }
00317 
00318 StringRef AttributeImpl::getKindAsString() const {
00319   assert(isStringAttribute());
00320   return static_cast<const StringAttributeImpl *>(this)->getStringKind();
00321 }
00322 
00323 StringRef AttributeImpl::getValueAsString() const {
00324   assert(isStringAttribute());
00325   return static_cast<const StringAttributeImpl *>(this)->getStringValue();
00326 }
00327 
00328 bool AttributeImpl::operator<(const AttributeImpl &AI) const {
00329   // This sorts the attributes with Attribute::AttrKinds coming first (sorted
00330   // relative to their enum value) and then strings.
00331   if (isEnumAttribute()) {
00332     if (AI.isEnumAttribute()) return getKindAsEnum() < AI.getKindAsEnum();
00333     if (AI.isAlignAttribute()) return true;
00334     if (AI.isStringAttribute()) return true;
00335   }
00336 
00337   if (isAlignAttribute()) {
00338     if (AI.isEnumAttribute()) return false;
00339     if (AI.isAlignAttribute()) return getValueAsInt() < AI.getValueAsInt();
00340     if (AI.isStringAttribute()) return true;
00341   }
00342 
00343   if (AI.isEnumAttribute()) return false;
00344   if (AI.isAlignAttribute()) return false;
00345   if (getKindAsString() == AI.getKindAsString())
00346     return getValueAsString() < AI.getValueAsString();
00347   return getKindAsString() < AI.getKindAsString();
00348 }
00349 
00350 uint64_t AttributeImpl::getAttrMask(Attribute::AttrKind Val) {
00351   // FIXME: Remove this.
00352   switch (Val) {
00353   case Attribute::EndAttrKinds:
00354     llvm_unreachable("Synthetic enumerators which should never get here");
00355 
00356   case Attribute::None:            return 0;
00357   case Attribute::ZExt:            return 1 << 0;
00358   case Attribute::SExt:            return 1 << 1;
00359   case Attribute::NoReturn:        return 1 << 2;
00360   case Attribute::InReg:           return 1 << 3;
00361   case Attribute::StructRet:       return 1 << 4;
00362   case Attribute::NoUnwind:        return 1 << 5;
00363   case Attribute::NoAlias:         return 1 << 6;
00364   case Attribute::ByVal:           return 1 << 7;
00365   case Attribute::Nest:            return 1 << 8;
00366   case Attribute::ReadNone:        return 1 << 9;
00367   case Attribute::ReadOnly:        return 1 << 10;
00368   case Attribute::NoInline:        return 1 << 11;
00369   case Attribute::AlwaysInline:    return 1 << 12;
00370   case Attribute::OptimizeForSize: return 1 << 13;
00371   case Attribute::StackProtect:    return 1 << 14;
00372   case Attribute::StackProtectReq: return 1 << 15;
00373   case Attribute::Alignment:       return 31 << 16;
00374   case Attribute::NoCapture:       return 1 << 21;
00375   case Attribute::NoRedZone:       return 1 << 22;
00376   case Attribute::NoImplicitFloat: return 1 << 23;
00377   case Attribute::Naked:           return 1 << 24;
00378   case Attribute::InlineHint:      return 1 << 25;
00379   case Attribute::StackAlignment:  return 7 << 26;
00380   case Attribute::ReturnsTwice:    return 1 << 29;
00381   case Attribute::UWTable:         return 1 << 30;
00382   case Attribute::NonLazyBind:     return 1U << 31;
00383   case Attribute::SanitizeAddress: return 1ULL << 32;
00384   case Attribute::MinSize:         return 1ULL << 33;
00385   case Attribute::NoDuplicate:     return 1ULL << 34;
00386   case Attribute::StackProtectStrong: return 1ULL << 35;
00387   case Attribute::SanitizeThread:  return 1ULL << 36;
00388   case Attribute::SanitizeMemory:  return 1ULL << 37;
00389   case Attribute::NoBuiltin:       return 1ULL << 38;
00390   case Attribute::Returned:        return 1ULL << 39;
00391   case Attribute::Cold:            return 1ULL << 40;
00392   case Attribute::Builtin:         return 1ULL << 41;
00393   case Attribute::OptimizeNone:    return 1ULL << 42;
00394   case Attribute::InAlloca:        return 1ULL << 43;
00395   }
00396   llvm_unreachable("Unsupported attribute type");
00397 }
00398 
00399 //===----------------------------------------------------------------------===//
00400 // AttributeSetNode Definition
00401 //===----------------------------------------------------------------------===//
00402 
00403 AttributeSetNode *AttributeSetNode::get(LLVMContext &C,
00404                                         ArrayRef<Attribute> Attrs) {
00405   if (Attrs.empty())
00406     return nullptr;
00407 
00408   // Otherwise, build a key to look up the existing attributes.
00409   LLVMContextImpl *pImpl = C.pImpl;
00410   FoldingSetNodeID ID;
00411 
00412   SmallVector<Attribute, 8> SortedAttrs(Attrs.begin(), Attrs.end());
00413   array_pod_sort(SortedAttrs.begin(), SortedAttrs.end());
00414 
00415   for (SmallVectorImpl<Attribute>::iterator I = SortedAttrs.begin(),
00416          E = SortedAttrs.end(); I != E; ++I)
00417     I->Profile(ID);
00418 
00419   void *InsertPoint;
00420   AttributeSetNode *PA =
00421     pImpl->AttrsSetNodes.FindNodeOrInsertPos(ID, InsertPoint);
00422 
00423   // If we didn't find any existing attributes of the same shape then create a
00424   // new one and insert it.
00425   if (!PA) {
00426     // Coallocate entries after the AttributeSetNode itself.
00427     void *Mem = ::operator new(sizeof(AttributeSetNode) +
00428                                sizeof(Attribute) * SortedAttrs.size());
00429     PA = new (Mem) AttributeSetNode(SortedAttrs);
00430     pImpl->AttrsSetNodes.InsertNode(PA, InsertPoint);
00431   }
00432 
00433   // Return the AttributesListNode that we found or created.
00434   return PA;
00435 }
00436 
00437 bool AttributeSetNode::hasAttribute(Attribute::AttrKind Kind) const {
00438   for (iterator I = begin(), E = end(); I != E; ++I)
00439     if (I->hasAttribute(Kind))
00440       return true;
00441   return false;
00442 }
00443 
00444 bool AttributeSetNode::hasAttribute(StringRef Kind) const {
00445   for (iterator I = begin(), E = end(); I != E; ++I)
00446     if (I->hasAttribute(Kind))
00447       return true;
00448   return false;
00449 }
00450 
00451 Attribute AttributeSetNode::getAttribute(Attribute::AttrKind Kind) const {
00452   for (iterator I = begin(), E = end(); I != E; ++I)
00453     if (I->hasAttribute(Kind))
00454       return *I;
00455   return Attribute();
00456 }
00457 
00458 Attribute AttributeSetNode::getAttribute(StringRef Kind) const {
00459   for (iterator I = begin(), E = end(); I != E; ++I)
00460     if (I->hasAttribute(Kind))
00461       return *I;
00462   return Attribute();
00463 }
00464 
00465 unsigned AttributeSetNode::getAlignment() const {
00466   for (iterator I = begin(), E = end(); I != E; ++I)
00467     if (I->hasAttribute(Attribute::Alignment))
00468       return I->getAlignment();
00469   return 0;
00470 }
00471 
00472 unsigned AttributeSetNode::getStackAlignment() const {
00473   for (iterator I = begin(), E = end(); I != E; ++I)
00474     if (I->hasAttribute(Attribute::StackAlignment))
00475       return I->getStackAlignment();
00476   return 0;
00477 }
00478 
00479 std::string AttributeSetNode::getAsString(bool InAttrGrp) const {
00480   std::string Str;
00481   for (iterator I = begin(), E = end(); I != E; ++I) {
00482     if (I != begin())
00483       Str += ' ';
00484     Str += I->getAsString(InAttrGrp);
00485   }
00486   return Str;
00487 }
00488 
00489 //===----------------------------------------------------------------------===//
00490 // AttributeSetImpl Definition
00491 //===----------------------------------------------------------------------===//
00492 
00493 uint64_t AttributeSetImpl::Raw(unsigned Index) const {
00494   for (unsigned I = 0, E = getNumAttributes(); I != E; ++I) {
00495     if (getSlotIndex(I) != Index) continue;
00496     const AttributeSetNode *ASN = getSlotNode(I);
00497     uint64_t Mask = 0;
00498 
00499     for (AttributeSetNode::iterator II = ASN->begin(),
00500            IE = ASN->end(); II != IE; ++II) {
00501       Attribute Attr = *II;
00502 
00503       // This cannot handle string attributes.
00504       if (Attr.isStringAttribute()) continue;
00505 
00506       Attribute::AttrKind Kind = Attr.getKindAsEnum();
00507 
00508       if (Kind == Attribute::Alignment)
00509         Mask |= (Log2_32(ASN->getAlignment()) + 1) << 16;
00510       else if (Kind == Attribute::StackAlignment)
00511         Mask |= (Log2_32(ASN->getStackAlignment()) + 1) << 26;
00512       else
00513         Mask |= AttributeImpl::getAttrMask(Kind);
00514     }
00515 
00516     return Mask;
00517   }
00518 
00519   return 0;
00520 }
00521 
00522 void AttributeSetImpl::dump() const {
00523   AttributeSet(const_cast<AttributeSetImpl *>(this)).dump();
00524 }
00525 
00526 //===----------------------------------------------------------------------===//
00527 // AttributeSet Construction and Mutation Methods
00528 //===----------------------------------------------------------------------===//
00529 
00530 AttributeSet
00531 AttributeSet::getImpl(LLVMContext &C,
00532                       ArrayRef<std::pair<unsigned, AttributeSetNode*> > Attrs) {
00533   LLVMContextImpl *pImpl = C.pImpl;
00534   FoldingSetNodeID ID;
00535   AttributeSetImpl::Profile(ID, Attrs);
00536 
00537   void *InsertPoint;
00538   AttributeSetImpl *PA = pImpl->AttrsLists.FindNodeOrInsertPos(ID, InsertPoint);
00539 
00540   // If we didn't find any existing attributes of the same shape then
00541   // create a new one and insert it.
00542   if (!PA) {
00543     // Coallocate entries after the AttributeSetImpl itself.
00544     void *Mem = ::operator new(sizeof(AttributeSetImpl) +
00545                                sizeof(std::pair<unsigned, AttributeSetNode *>) *
00546                                    Attrs.size());
00547     PA = new (Mem) AttributeSetImpl(C, Attrs);
00548     pImpl->AttrsLists.InsertNode(PA, InsertPoint);
00549   }
00550 
00551   // Return the AttributesList that we found or created.
00552   return AttributeSet(PA);
00553 }
00554 
00555 AttributeSet AttributeSet::get(LLVMContext &C,
00556                                ArrayRef<std::pair<unsigned, Attribute> > Attrs){
00557   // If there are no attributes then return a null AttributesList pointer.
00558   if (Attrs.empty())
00559     return AttributeSet();
00560 
00561 #ifndef NDEBUG
00562   for (unsigned i = 0, e = Attrs.size(); i != e; ++i) {
00563     assert((!i || Attrs[i-1].first <= Attrs[i].first) &&
00564            "Misordered Attributes list!");
00565     assert(!Attrs[i].second.hasAttribute(Attribute::None) &&
00566            "Pointless attribute!");
00567   }
00568 #endif
00569 
00570   // Create a vector if (unsigned, AttributeSetNode*) pairs from the attributes
00571   // list.
00572   SmallVector<std::pair<unsigned, AttributeSetNode*>, 8> AttrPairVec;
00573   for (ArrayRef<std::pair<unsigned, Attribute> >::iterator I = Attrs.begin(),
00574          E = Attrs.end(); I != E; ) {
00575     unsigned Index = I->first;
00576     SmallVector<Attribute, 4> AttrVec;
00577     while (I != E && I->first == Index) {
00578       AttrVec.push_back(I->second);
00579       ++I;
00580     }
00581 
00582     AttrPairVec.push_back(std::make_pair(Index,
00583                                          AttributeSetNode::get(C, AttrVec)));
00584   }
00585 
00586   return getImpl(C, AttrPairVec);
00587 }
00588 
00589 AttributeSet AttributeSet::get(LLVMContext &C,
00590                                ArrayRef<std::pair<unsigned,
00591                                                   AttributeSetNode*> > Attrs) {
00592   // If there are no attributes then return a null AttributesList pointer.
00593   if (Attrs.empty())
00594     return AttributeSet();
00595 
00596   return getImpl(C, Attrs);
00597 }
00598 
00599 AttributeSet AttributeSet::get(LLVMContext &C, unsigned Index, AttrBuilder &B) {
00600   if (!B.hasAttributes())
00601     return AttributeSet();
00602 
00603   // Add target-independent attributes.
00604   SmallVector<std::pair<unsigned, Attribute>, 8> Attrs;
00605   for (Attribute::AttrKind Kind = Attribute::None;
00606        Kind != Attribute::EndAttrKinds; Kind = Attribute::AttrKind(Kind + 1)) {
00607     if (!B.contains(Kind))
00608       continue;
00609 
00610     if (Kind == Attribute::Alignment)
00611       Attrs.push_back(std::make_pair(Index, Attribute::
00612                                      getWithAlignment(C, B.getAlignment())));
00613     else if (Kind == Attribute::StackAlignment)
00614       Attrs.push_back(std::make_pair(Index, Attribute::
00615                               getWithStackAlignment(C, B.getStackAlignment())));
00616     else
00617       Attrs.push_back(std::make_pair(Index, Attribute::get(C, Kind)));
00618   }
00619 
00620   // Add target-dependent (string) attributes.
00621   for (AttrBuilder::td_iterator I = B.td_begin(), E = B.td_end();
00622        I != E; ++I)
00623     Attrs.push_back(std::make_pair(Index, Attribute::get(C, I->first,I->second)));
00624 
00625   return get(C, Attrs);
00626 }
00627 
00628 AttributeSet AttributeSet::get(LLVMContext &C, unsigned Index,
00629                                ArrayRef<Attribute::AttrKind> Kind) {
00630   SmallVector<std::pair<unsigned, Attribute>, 8> Attrs;
00631   for (ArrayRef<Attribute::AttrKind>::iterator I = Kind.begin(),
00632          E = Kind.end(); I != E; ++I)
00633     Attrs.push_back(std::make_pair(Index, Attribute::get(C, *I)));
00634   return get(C, Attrs);
00635 }
00636 
00637 AttributeSet AttributeSet::get(LLVMContext &C, ArrayRef<AttributeSet> Attrs) {
00638   if (Attrs.empty()) return AttributeSet();
00639   if (Attrs.size() == 1) return Attrs[0];
00640 
00641   SmallVector<std::pair<unsigned, AttributeSetNode*>, 8> AttrNodeVec;
00642   AttributeSetImpl *A0 = Attrs[0].pImpl;
00643   if (A0)
00644     AttrNodeVec.append(A0->getNode(0), A0->getNode(A0->getNumAttributes()));
00645   // Copy all attributes from Attrs into AttrNodeVec while keeping AttrNodeVec
00646   // ordered by index.  Because we know that each list in Attrs is ordered by
00647   // index we only need to merge each successive list in rather than doing a
00648   // full sort.
00649   for (unsigned I = 1, E = Attrs.size(); I != E; ++I) {
00650     AttributeSetImpl *AS = Attrs[I].pImpl;
00651     if (!AS) continue;
00652     SmallVector<std::pair<unsigned, AttributeSetNode *>, 8>::iterator
00653       ANVI = AttrNodeVec.begin(), ANVE;
00654     for (const AttributeSetImpl::IndexAttrPair
00655              *AI = AS->getNode(0),
00656              *AE = AS->getNode(AS->getNumAttributes());
00657          AI != AE; ++AI) {
00658       ANVE = AttrNodeVec.end();
00659       while (ANVI != ANVE && ANVI->first <= AI->first)
00660         ++ANVI;
00661       ANVI = AttrNodeVec.insert(ANVI, *AI) + 1;
00662     }
00663   }
00664 
00665   return getImpl(C, AttrNodeVec);
00666 }
00667 
00668 AttributeSet AttributeSet::addAttribute(LLVMContext &C, unsigned Index,
00669                                         Attribute::AttrKind Attr) const {
00670   if (hasAttribute(Index, Attr)) return *this;
00671   return addAttributes(C, Index, AttributeSet::get(C, Index, Attr));
00672 }
00673 
00674 AttributeSet AttributeSet::addAttribute(LLVMContext &C, unsigned Index,
00675                                         StringRef Kind) const {
00676   llvm::AttrBuilder B;
00677   B.addAttribute(Kind);
00678   return addAttributes(C, Index, AttributeSet::get(C, Index, B));
00679 }
00680 
00681 AttributeSet AttributeSet::addAttribute(LLVMContext &C, unsigned Index,
00682                                         StringRef Kind, StringRef Value) const {
00683   llvm::AttrBuilder B;
00684   B.addAttribute(Kind, Value);
00685   return addAttributes(C, Index, AttributeSet::get(C, Index, B));
00686 }
00687 
00688 AttributeSet AttributeSet::addAttributes(LLVMContext &C, unsigned Index,
00689                                          AttributeSet Attrs) const {
00690   if (!pImpl) return Attrs;
00691   if (!Attrs.pImpl) return *this;
00692 
00693 #ifndef NDEBUG
00694   // FIXME it is not obvious how this should work for alignment. For now, say
00695   // we can't change a known alignment.
00696   unsigned OldAlign = getParamAlignment(Index);
00697   unsigned NewAlign = Attrs.getParamAlignment(Index);
00698   assert((!OldAlign || !NewAlign || OldAlign == NewAlign) &&
00699          "Attempt to change alignment!");
00700 #endif
00701 
00702   // Add the attribute slots before the one we're trying to add.
00703   SmallVector<AttributeSet, 4> AttrSet;
00704   uint64_t NumAttrs = pImpl->getNumAttributes();
00705   AttributeSet AS;
00706   uint64_t LastIndex = 0;
00707   for (unsigned I = 0, E = NumAttrs; I != E; ++I) {
00708     if (getSlotIndex(I) >= Index) {
00709       if (getSlotIndex(I) == Index) AS = getSlotAttributes(LastIndex++);
00710       break;
00711     }
00712     LastIndex = I + 1;
00713     AttrSet.push_back(getSlotAttributes(I));
00714   }
00715 
00716   // Now add the attribute into the correct slot. There may already be an
00717   // AttributeSet there.
00718   AttrBuilder B(AS, Index);
00719 
00720   for (unsigned I = 0, E = Attrs.pImpl->getNumAttributes(); I != E; ++I)
00721     if (Attrs.getSlotIndex(I) == Index) {
00722       for (AttributeSetImpl::iterator II = Attrs.pImpl->begin(I),
00723              IE = Attrs.pImpl->end(I); II != IE; ++II)
00724         B.addAttribute(*II);
00725       break;
00726     }
00727 
00728   AttrSet.push_back(AttributeSet::get(C, Index, B));
00729 
00730   // Add the remaining attribute slots.
00731   for (unsigned I = LastIndex, E = NumAttrs; I < E; ++I)
00732     AttrSet.push_back(getSlotAttributes(I));
00733 
00734   return get(C, AttrSet);
00735 }
00736 
00737 AttributeSet AttributeSet::removeAttribute(LLVMContext &C, unsigned Index,
00738                                            Attribute::AttrKind Attr) const {
00739   if (!hasAttribute(Index, Attr)) return *this;
00740   return removeAttributes(C, Index, AttributeSet::get(C, Index, Attr));
00741 }
00742 
00743 AttributeSet AttributeSet::removeAttributes(LLVMContext &C, unsigned Index,
00744                                             AttributeSet Attrs) const {
00745   if (!pImpl) return AttributeSet();
00746   if (!Attrs.pImpl) return *this;
00747 
00748 #ifndef NDEBUG
00749   // FIXME it is not obvious how this should work for alignment.
00750   // For now, say we can't pass in alignment, which no current use does.
00751   assert(!Attrs.hasAttribute(Index, Attribute::Alignment) &&
00752          "Attempt to change alignment!");
00753 #endif
00754 
00755   // Add the attribute slots before the one we're trying to add.
00756   SmallVector<AttributeSet, 4> AttrSet;
00757   uint64_t NumAttrs = pImpl->getNumAttributes();
00758   AttributeSet AS;
00759   uint64_t LastIndex = 0;
00760   for (unsigned I = 0, E = NumAttrs; I != E; ++I) {
00761     if (getSlotIndex(I) >= Index) {
00762       if (getSlotIndex(I) == Index) AS = getSlotAttributes(LastIndex++);
00763       break;
00764     }
00765     LastIndex = I + 1;
00766     AttrSet.push_back(getSlotAttributes(I));
00767   }
00768 
00769   // Now remove the attribute from the correct slot. There may already be an
00770   // AttributeSet there.
00771   AttrBuilder B(AS, Index);
00772 
00773   for (unsigned I = 0, E = Attrs.pImpl->getNumAttributes(); I != E; ++I)
00774     if (Attrs.getSlotIndex(I) == Index) {
00775       B.removeAttributes(Attrs.pImpl->getSlotAttributes(I), Index);
00776       break;
00777     }
00778 
00779   AttrSet.push_back(AttributeSet::get(C, Index, B));
00780 
00781   // Add the remaining attribute slots.
00782   for (unsigned I = LastIndex, E = NumAttrs; I < E; ++I)
00783     AttrSet.push_back(getSlotAttributes(I));
00784 
00785   return get(C, AttrSet);
00786 }
00787 
00788 //===----------------------------------------------------------------------===//
00789 // AttributeSet Accessor Methods
00790 //===----------------------------------------------------------------------===//
00791 
00792 LLVMContext &AttributeSet::getContext() const {
00793   return pImpl->getContext();
00794 }
00795 
00796 AttributeSet AttributeSet::getParamAttributes(unsigned Index) const {
00797   return pImpl && hasAttributes(Index) ?
00798     AttributeSet::get(pImpl->getContext(),
00799                       ArrayRef<std::pair<unsigned, AttributeSetNode*> >(
00800                         std::make_pair(Index, getAttributes(Index)))) :
00801     AttributeSet();
00802 }
00803 
00804 AttributeSet AttributeSet::getRetAttributes() const {
00805   return pImpl && hasAttributes(ReturnIndex) ?
00806     AttributeSet::get(pImpl->getContext(),
00807                       ArrayRef<std::pair<unsigned, AttributeSetNode*> >(
00808                         std::make_pair(ReturnIndex,
00809                                        getAttributes(ReturnIndex)))) :
00810     AttributeSet();
00811 }
00812 
00813 AttributeSet AttributeSet::getFnAttributes() const {
00814   return pImpl && hasAttributes(FunctionIndex) ?
00815     AttributeSet::get(pImpl->getContext(),
00816                       ArrayRef<std::pair<unsigned, AttributeSetNode*> >(
00817                         std::make_pair(FunctionIndex,
00818                                        getAttributes(FunctionIndex)))) :
00819     AttributeSet();
00820 }
00821 
00822 bool AttributeSet::hasAttribute(unsigned Index, Attribute::AttrKind Kind) const{
00823   AttributeSetNode *ASN = getAttributes(Index);
00824   return ASN ? ASN->hasAttribute(Kind) : false;
00825 }
00826 
00827 bool AttributeSet::hasAttribute(unsigned Index, StringRef Kind) const {
00828   AttributeSetNode *ASN = getAttributes(Index);
00829   return ASN ? ASN->hasAttribute(Kind) : false;
00830 }
00831 
00832 bool AttributeSet::hasAttributes(unsigned Index) const {
00833   AttributeSetNode *ASN = getAttributes(Index);
00834   return ASN ? ASN->hasAttributes() : false;
00835 }
00836 
00837 /// \brief Return true if the specified attribute is set for at least one
00838 /// parameter or for the return value.
00839 bool AttributeSet::hasAttrSomewhere(Attribute::AttrKind Attr) const {
00840   if (!pImpl) return false;
00841 
00842   for (unsigned I = 0, E = pImpl->getNumAttributes(); I != E; ++I)
00843     for (AttributeSetImpl::iterator II = pImpl->begin(I),
00844            IE = pImpl->end(I); II != IE; ++II)
00845       if (II->hasAttribute(Attr))
00846         return true;
00847 
00848   return false;
00849 }
00850 
00851 Attribute AttributeSet::getAttribute(unsigned Index,
00852                                      Attribute::AttrKind Kind) const {
00853   AttributeSetNode *ASN = getAttributes(Index);
00854   return ASN ? ASN->getAttribute(Kind) : Attribute();
00855 }
00856 
00857 Attribute AttributeSet::getAttribute(unsigned Index,
00858                                      StringRef Kind) const {
00859   AttributeSetNode *ASN = getAttributes(Index);
00860   return ASN ? ASN->getAttribute(Kind) : Attribute();
00861 }
00862 
00863 unsigned AttributeSet::getParamAlignment(unsigned Index) const {
00864   AttributeSetNode *ASN = getAttributes(Index);
00865   return ASN ? ASN->getAlignment() : 0;
00866 }
00867 
00868 unsigned AttributeSet::getStackAlignment(unsigned Index) const {
00869   AttributeSetNode *ASN = getAttributes(Index);
00870   return ASN ? ASN->getStackAlignment() : 0;
00871 }
00872 
00873 std::string AttributeSet::getAsString(unsigned Index,
00874                                       bool InAttrGrp) const {
00875   AttributeSetNode *ASN = getAttributes(Index);
00876   return ASN ? ASN->getAsString(InAttrGrp) : std::string("");
00877 }
00878 
00879 /// \brief The attributes for the specified index are returned.
00880 AttributeSetNode *AttributeSet::getAttributes(unsigned Index) const {
00881   if (!pImpl) return nullptr;
00882 
00883   // Loop through to find the attribute node we want.
00884   for (unsigned I = 0, E = pImpl->getNumAttributes(); I != E; ++I)
00885     if (pImpl->getSlotIndex(I) == Index)
00886       return pImpl->getSlotNode(I);
00887 
00888   return nullptr;
00889 }
00890 
00891 AttributeSet::iterator AttributeSet::begin(unsigned Slot) const {
00892   if (!pImpl)
00893     return ArrayRef<Attribute>().begin();
00894   return pImpl->begin(Slot);
00895 }
00896 
00897 AttributeSet::iterator AttributeSet::end(unsigned Slot) const {
00898   if (!pImpl)
00899     return ArrayRef<Attribute>().end();
00900   return pImpl->end(Slot);
00901 }
00902 
00903 //===----------------------------------------------------------------------===//
00904 // AttributeSet Introspection Methods
00905 //===----------------------------------------------------------------------===//
00906 
00907 /// \brief Return the number of slots used in this attribute list.  This is the
00908 /// number of arguments that have an attribute set on them (including the
00909 /// function itself).
00910 unsigned AttributeSet::getNumSlots() const {
00911   return pImpl ? pImpl->getNumAttributes() : 0;
00912 }
00913 
00914 unsigned AttributeSet::getSlotIndex(unsigned Slot) const {
00915   assert(pImpl && Slot < pImpl->getNumAttributes() &&
00916          "Slot # out of range!");
00917   return pImpl->getSlotIndex(Slot);
00918 }
00919 
00920 AttributeSet AttributeSet::getSlotAttributes(unsigned Slot) const {
00921   assert(pImpl && Slot < pImpl->getNumAttributes() &&
00922          "Slot # out of range!");
00923   return pImpl->getSlotAttributes(Slot);
00924 }
00925 
00926 uint64_t AttributeSet::Raw(unsigned Index) const {
00927   // FIXME: Remove this.
00928   return pImpl ? pImpl->Raw(Index) : 0;
00929 }
00930 
00931 void AttributeSet::dump() const {
00932   dbgs() << "PAL[\n";
00933 
00934   for (unsigned i = 0, e = getNumSlots(); i < e; ++i) {
00935     uint64_t Index = getSlotIndex(i);
00936     dbgs() << "  { ";
00937     if (Index == ~0U)
00938       dbgs() << "~0U";
00939     else
00940       dbgs() << Index;
00941     dbgs() << " => " << getAsString(Index) << " }\n";
00942   }
00943 
00944   dbgs() << "]\n";
00945 }
00946 
00947 //===----------------------------------------------------------------------===//
00948 // AttrBuilder Method Implementations
00949 //===----------------------------------------------------------------------===//
00950 
00951 AttrBuilder::AttrBuilder(AttributeSet AS, unsigned Index)
00952   : Attrs(0), Alignment(0), StackAlignment(0) {
00953   AttributeSetImpl *pImpl = AS.pImpl;
00954   if (!pImpl) return;
00955 
00956   for (unsigned I = 0, E = pImpl->getNumAttributes(); I != E; ++I) {
00957     if (pImpl->getSlotIndex(I) != Index) continue;
00958 
00959     for (AttributeSetImpl::iterator II = pImpl->begin(I),
00960            IE = pImpl->end(I); II != IE; ++II)
00961       addAttribute(*II);
00962 
00963     break;
00964   }
00965 }
00966 
00967 void AttrBuilder::clear() {
00968   Attrs.reset();
00969   Alignment = StackAlignment = 0;
00970 }
00971 
00972 AttrBuilder &AttrBuilder::addAttribute(Attribute::AttrKind Val) {
00973   assert((unsigned)Val < Attribute::EndAttrKinds && "Attribute out of range!");
00974   assert(Val != Attribute::Alignment && Val != Attribute::StackAlignment &&
00975          "Adding alignment attribute without adding alignment value!");
00976   Attrs[Val] = true;
00977   return *this;
00978 }
00979 
00980 AttrBuilder &AttrBuilder::addAttribute(Attribute Attr) {
00981   if (Attr.isStringAttribute()) {
00982     addAttribute(Attr.getKindAsString(), Attr.getValueAsString());
00983     return *this;
00984   }
00985 
00986   Attribute::AttrKind Kind = Attr.getKindAsEnum();
00987   Attrs[Kind] = true;
00988 
00989   if (Kind == Attribute::Alignment)
00990     Alignment = Attr.getAlignment();
00991   else if (Kind == Attribute::StackAlignment)
00992     StackAlignment = Attr.getStackAlignment();
00993   return *this;
00994 }
00995 
00996 AttrBuilder &AttrBuilder::addAttribute(StringRef A, StringRef V) {
00997   TargetDepAttrs[A] = V;
00998   return *this;
00999 }
01000 
01001 AttrBuilder &AttrBuilder::removeAttribute(Attribute::AttrKind Val) {
01002   assert((unsigned)Val < Attribute::EndAttrKinds && "Attribute out of range!");
01003   Attrs[Val] = false;
01004 
01005   if (Val == Attribute::Alignment)
01006     Alignment = 0;
01007   else if (Val == Attribute::StackAlignment)
01008     StackAlignment = 0;
01009 
01010   return *this;
01011 }
01012 
01013 AttrBuilder &AttrBuilder::removeAttributes(AttributeSet A, uint64_t Index) {
01014   unsigned Slot = ~0U;
01015   for (unsigned I = 0, E = A.getNumSlots(); I != E; ++I)
01016     if (A.getSlotIndex(I) == Index) {
01017       Slot = I;
01018       break;
01019     }
01020 
01021   assert(Slot != ~0U && "Couldn't find index in AttributeSet!");
01022 
01023   for (AttributeSet::iterator I = A.begin(Slot), E = A.end(Slot); I != E; ++I) {
01024     Attribute Attr = *I;
01025     if (Attr.isEnumAttribute() || Attr.isAlignAttribute()) {
01026       Attribute::AttrKind Kind = I->getKindAsEnum();
01027       Attrs[Kind] = false;
01028 
01029       if (Kind == Attribute::Alignment)
01030         Alignment = 0;
01031       else if (Kind == Attribute::StackAlignment)
01032         StackAlignment = 0;
01033     } else {
01034       assert(Attr.isStringAttribute() && "Invalid attribute type!");
01035       std::map<std::string, std::string>::iterator
01036         Iter = TargetDepAttrs.find(Attr.getKindAsString());
01037       if (Iter != TargetDepAttrs.end())
01038         TargetDepAttrs.erase(Iter);
01039     }
01040   }
01041 
01042   return *this;
01043 }
01044 
01045 AttrBuilder &AttrBuilder::removeAttribute(StringRef A) {
01046   std::map<std::string, std::string>::iterator I = TargetDepAttrs.find(A);
01047   if (I != TargetDepAttrs.end())
01048     TargetDepAttrs.erase(I);
01049   return *this;
01050 }
01051 
01052 AttrBuilder &AttrBuilder::addAlignmentAttr(unsigned Align) {
01053   if (Align == 0) return *this;
01054 
01055   assert(isPowerOf2_32(Align) && "Alignment must be a power of two.");
01056   assert(Align <= 0x40000000 && "Alignment too large.");
01057 
01058   Attrs[Attribute::Alignment] = true;
01059   Alignment = Align;
01060   return *this;
01061 }
01062 
01063 AttrBuilder &AttrBuilder::addStackAlignmentAttr(unsigned Align) {
01064   // Default alignment, allow the target to define how to align it.
01065   if (Align == 0) return *this;
01066 
01067   assert(isPowerOf2_32(Align) && "Alignment must be a power of two.");
01068   assert(Align <= 0x100 && "Alignment too large.");
01069 
01070   Attrs[Attribute::StackAlignment] = true;
01071   StackAlignment = Align;
01072   return *this;
01073 }
01074 
01075 AttrBuilder &AttrBuilder::merge(const AttrBuilder &B) {
01076   // FIXME: What if both have alignments, but they don't match?!
01077   if (!Alignment)
01078     Alignment = B.Alignment;
01079 
01080   if (!StackAlignment)
01081     StackAlignment = B.StackAlignment;
01082 
01083   Attrs |= B.Attrs;
01084 
01085   for (td_const_iterator I = B.TargetDepAttrs.begin(),
01086          E = B.TargetDepAttrs.end(); I != E; ++I)
01087     TargetDepAttrs[I->first] = I->second;
01088 
01089   return *this;
01090 }
01091 
01092 bool AttrBuilder::contains(StringRef A) const {
01093   return TargetDepAttrs.find(A) != TargetDepAttrs.end();
01094 }
01095 
01096 bool AttrBuilder::hasAttributes() const {
01097   return !Attrs.none() || !TargetDepAttrs.empty();
01098 }
01099 
01100 bool AttrBuilder::hasAttributes(AttributeSet A, uint64_t Index) const {
01101   unsigned Slot = ~0U;
01102   for (unsigned I = 0, E = A.getNumSlots(); I != E; ++I)
01103     if (A.getSlotIndex(I) == Index) {
01104       Slot = I;
01105       break;
01106     }
01107 
01108   assert(Slot != ~0U && "Couldn't find the index!");
01109 
01110   for (AttributeSet::iterator I = A.begin(Slot), E = A.end(Slot);
01111        I != E; ++I) {
01112     Attribute Attr = *I;
01113     if (Attr.isEnumAttribute() || Attr.isAlignAttribute()) {
01114       if (Attrs[I->getKindAsEnum()])
01115         return true;
01116     } else {
01117       assert(Attr.isStringAttribute() && "Invalid attribute kind!");
01118       return TargetDepAttrs.find(Attr.getKindAsString())!=TargetDepAttrs.end();
01119     }
01120   }
01121 
01122   return false;
01123 }
01124 
01125 bool AttrBuilder::hasAlignmentAttr() const {
01126   return Alignment != 0;
01127 }
01128 
01129 bool AttrBuilder::operator==(const AttrBuilder &B) {
01130   if (Attrs != B.Attrs)
01131     return false;
01132 
01133   for (td_const_iterator I = TargetDepAttrs.begin(),
01134          E = TargetDepAttrs.end(); I != E; ++I)
01135     if (B.TargetDepAttrs.find(I->first) == B.TargetDepAttrs.end())
01136       return false;
01137 
01138   return Alignment == B.Alignment && StackAlignment == B.StackAlignment;
01139 }
01140 
01141 AttrBuilder &AttrBuilder::addRawValue(uint64_t Val) {
01142   // FIXME: Remove this in 4.0.
01143   if (!Val) return *this;
01144 
01145   for (Attribute::AttrKind I = Attribute::None; I != Attribute::EndAttrKinds;
01146        I = Attribute::AttrKind(I + 1)) {
01147     if (uint64_t A = (Val & AttributeImpl::getAttrMask(I))) {
01148       Attrs[I] = true;
01149  
01150       if (I == Attribute::Alignment)
01151         Alignment = 1ULL << ((A >> 16) - 1);
01152       else if (I == Attribute::StackAlignment)
01153         StackAlignment = 1ULL << ((A >> 26)-1);
01154     }
01155   }
01156  
01157   return *this;
01158 }
01159 
01160 //===----------------------------------------------------------------------===//
01161 // AttributeFuncs Function Defintions
01162 //===----------------------------------------------------------------------===//
01163 
01164 /// \brief Which attributes cannot be applied to a type.
01165 AttributeSet AttributeFuncs::typeIncompatible(Type *Ty, uint64_t Index) {
01166   AttrBuilder Incompatible;
01167 
01168   if (!Ty->isIntegerTy())
01169     // Attribute that only apply to integers.
01170     Incompatible.addAttribute(Attribute::SExt)
01171       .addAttribute(Attribute::ZExt);
01172 
01173   if (!Ty->isPointerTy())
01174     // Attribute that only apply to pointers.
01175     Incompatible.addAttribute(Attribute::ByVal)
01176       .addAttribute(Attribute::Nest)
01177       .addAttribute(Attribute::NoAlias)
01178       .addAttribute(Attribute::NoCapture)
01179       .addAttribute(Attribute::ReadNone)
01180       .addAttribute(Attribute::ReadOnly)
01181       .addAttribute(Attribute::StructRet)
01182       .addAttribute(Attribute::InAlloca);
01183 
01184   return AttributeSet::get(Ty->getContext(), Index, Incompatible);
01185 }