X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FVMCore%2FAttributes.cpp;h=b728b9284b4499fa701d7cc864a8d5584ce40c2d;hb=0e64f810a521806838bf90d77f081d3a1da98b5e;hp=0a0d0a842d0dbc36aa39cbe3a301757092511687;hpb=e642658480ed0c9cde023a165edca237ba90bd31;p=oota-llvm.git diff --git a/lib/VMCore/Attributes.cpp b/lib/VMCore/Attributes.cpp index 0a0d0a842d0..b728b9284b4 100644 --- a/lib/VMCore/Attributes.cpp +++ b/lib/VMCore/Attributes.cpp @@ -15,8 +15,11 @@ #include "llvm/Type.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/FoldingSet.h" -#include "llvm/Support/Streams.h" +#include "llvm/Support/Atomic.h" +#include "llvm/Support/Mutex.h" +#include "llvm/Support/Debug.h" #include "llvm/Support/ManagedStatic.h" +#include "llvm/Support/raw_ostream.h" using namespace llvm; //===----------------------------------------------------------------------===// @@ -33,6 +36,8 @@ std::string Attribute::getAsString(Attributes Attrs) { Result += "noreturn "; if (Attrs & Attribute::NoUnwind) Result += "nounwind "; + if (Attrs & Attribute::UWTable) + Result += "uwtable "; if (Attrs & Attribute::InReg) Result += "inreg "; if (Attrs & Attribute::NoAlias) @@ -40,7 +45,7 @@ std::string Attribute::getAsString(Attributes Attrs) { if (Attrs & Attribute::NoCapture) Result += "nocapture "; if (Attrs & Attribute::StructRet) - Result += "sret "; + Result += "sret "; if (Attrs & Attribute::ByVal) Result += "byval "; if (Attrs & Attribute::Nest) @@ -53,15 +58,32 @@ std::string Attribute::getAsString(Attributes Attrs) { Result += "optsize "; if (Attrs & Attribute::NoInline) Result += "noinline "; + if (Attrs & Attribute::InlineHint) + Result += "inlinehint "; if (Attrs & Attribute::AlwaysInline) Result += "alwaysinline "; if (Attrs & Attribute::StackProtect) Result += "ssp "; if (Attrs & Attribute::StackProtectReq) Result += "sspreq "; + if (Attrs & Attribute::NoRedZone) + Result += "noredzone "; + if (Attrs & Attribute::NoImplicitFloat) + Result += "noimplicitfloat "; + if (Attrs & Attribute::Naked) + Result += "naked "; + if (Attrs & Attribute::Hotpatch) + Result += "hotpatch "; + if (Attrs & Attribute::NonLazyBind) + Result += "nonlazybind "; + if (Attrs & Attribute::StackAlignment) { + Result += "alignstack("; + Result += utostr(Attribute::getStackAlignmentFromAttrs(Attrs)); + Result += ") "; + } if (Attrs & Attribute::Alignment) { Result += "align "; - Result += utostr(1ull << ((Attrs & Attribute::Alignment)>>16)); + Result += utostr(Attribute::getAlignmentFromAttrs(Attrs)); Result += " "; } // Trim the trailing space. @@ -70,14 +92,14 @@ std::string Attribute::getAsString(Attributes Attrs) { return Result; } -Attributes Attribute::typeIncompatible(const Type *Ty) { +Attributes Attribute::typeIncompatible(Type *Ty) { Attributes Incompatible = None; - if (!Ty->isInteger()) + if (!Ty->isIntegerTy()) // Attributes that only apply to integers. Incompatible |= SExt | ZExt; - if (!isa(Ty)) + if (!Ty->isPointerTy()) // Attributes that only apply to pointers. Incompatible |= ByVal | Nest | NoAlias | StructRet | NoCapture; @@ -89,8 +111,16 @@ Attributes Attribute::typeIncompatible(const Type *Ty) { //===----------------------------------------------------------------------===// namespace llvm { + class AttributeListImpl; +} + +static ManagedStatic > AttributesLists; + +namespace llvm { +static ManagedStatic > ALMutex; + class AttributeListImpl : public FoldingSetNode { - unsigned RefCount; + sys::cas_flag RefCount; // AttributesList is uniqued, these should not be publicly available. void operator=(const AttributeListImpl &); // Do not implement @@ -104,11 +134,21 @@ public: RefCount = 0; } - void AddRef() { ++RefCount; } - void DropRef() { if (--RefCount == 0) delete this; } + void AddRef() { + sys::SmartScopedLock Lock(*ALMutex); + ++RefCount; + } + void DropRef() { + sys::SmartScopedLock Lock(*ALMutex); + if (!AttributesLists.isConstructed()) + return; + sys::cas_flag new_val = --RefCount; + if (new_val == 0) + delete this; + } void Profile(FoldingSetNodeID &ID) const { - Profile(ID, &Attrs[0], Attrs.size()); + Profile(ID, Attrs.data(), Attrs.size()); } static void Profile(FoldingSetNodeID &ID, const AttributeWithIndex *Attr, unsigned NumAttrs) { @@ -118,9 +158,8 @@ public: }; } -static ManagedStatic > AttributesLists; - AttributeListImpl::~AttributeListImpl() { + // NOTE: Lock must be acquired by caller. AttributesLists->RemoveNode(this); } @@ -143,6 +182,9 @@ AttrListPtr AttrListPtr::get(const AttributeWithIndex *Attrs, unsigned NumAttrs) FoldingSetNodeID ID; AttributeListImpl::Profile(ID, Attrs, NumAttrs); void *InsertPos; + + sys::SmartScopedLock Lock(*ALMutex); + AttributeListImpl *PAL = AttributesLists->FindNodeOrInsertPos(ID, InsertPos); @@ -171,6 +213,7 @@ AttrListPtr::AttrListPtr(const AttrListPtr &P) : AttrList(P.AttrList) { } const AttrListPtr &AttrListPtr::operator=(const AttrListPtr &RHS) { + sys::SmartScopedLock Lock(*ALMutex); if (AttrList == RHS.AttrList) return *this; if (AttrList) AttrList->DropRef(); AttrList = RHS.AttrList; @@ -261,7 +304,7 @@ AttrListPtr AttrListPtr::addAttr(unsigned Idx, Attributes Attrs) const { OldAttrList.begin()+i, OldAttrList.end()); } - return get(&NewAttrList[0], NewAttrList.size()); + return get(NewAttrList.data(), NewAttrList.size()); } AttrListPtr AttrListPtr::removeAttr(unsigned Idx, Attributes Attrs) const { @@ -296,15 +339,15 @@ AttrListPtr AttrListPtr::removeAttr(unsigned Idx, Attributes Attrs) const { NewAttrList.insert(NewAttrList.end(), OldAttrList.begin()+i, OldAttrList.end()); - return get(&NewAttrList[0], NewAttrList.size()); + return get(NewAttrList.data(), NewAttrList.size()); } void AttrListPtr::dump() const { - cerr << "PAL[ "; + dbgs() << "PAL[ "; for (unsigned i = 0; i < getNumSlots(); ++i) { const AttributeWithIndex &PAWI = getSlot(i); - cerr << "{" << PAWI.Index << "," << PAWI.Attrs << "} "; + dbgs() << "{" << PAWI.Index << "," << PAWI.Attrs << "} "; } - cerr << "]\n"; + dbgs() << "]\n"; }