diff options
Diffstat (limited to 'lib/VMCore/Attributes.cpp')
-rw-r--r-- | lib/VMCore/Attributes.cpp | 41 |
1 files changed, 37 insertions, 4 deletions
diff --git a/lib/VMCore/Attributes.cpp b/lib/VMCore/Attributes.cpp index af8163fd40..7d3197cb0d 100644 --- a/lib/VMCore/Attributes.cpp +++ b/lib/VMCore/Attributes.cpp @@ -12,6 +12,8 @@ //===----------------------------------------------------------------------===// #include "llvm/Attributes.h" +#include "AttributesImpl.h" +#include "LLVMContextImpl.h" #include "llvm/Type.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/FoldingSet.h" @@ -94,21 +96,52 @@ std::string Attributes::getAsString() const { return Result; } -Attributes Attribute::typeIncompatible(Type *Ty) { - Attributes Incompatible = None; +Attributes Attributes::typeIncompatible(Type *Ty) { + Attributes Incompatible = Attribute::None; if (!Ty->isIntegerTy()) // Attributes that only apply to integers. - Incompatible |= SExt | ZExt; + Incompatible |= Attribute::SExt | Attribute::ZExt; if (!Ty->isPointerTy()) // Attributes that only apply to pointers. - Incompatible |= ByVal | Nest | NoAlias | StructRet | NoCapture; + Incompatible |= Attribute::ByVal | Attribute::Nest | Attribute::NoAlias | + Attribute::StructRet | Attribute::NoCapture; return Incompatible; } //===----------------------------------------------------------------------===// +// AttributeImpl Definition +//===----------------------------------------------------------------------===// + +Attributes::Attributes(AttributesImpl *A) : Bits(0) {} + +Attributes Attributes::get(LLVMContext &Context, Attributes::Builder &B) { + // If there are no attributes, return an empty Attributes class. + if (B.Bits == 0) + return Attributes(); + + // Otherwise, build a key to look up the existing attributes. + LLVMContextImpl *pImpl = Context.pImpl; + FoldingSetNodeID ID; + ID.AddInteger(B.Bits); + + void *InsertPoint; + AttributesImpl *PA = pImpl->AttrsSet.FindNodeOrInsertPos(ID, InsertPoint); + + if (!PA) { + // If we didn't find any existing attributes of the same shape then create a + // new one and insert it. + PA = new AttributesImpl(B.Bits); + pImpl->AttrsSet.InsertNode(PA, InsertPoint); + } + + // Return the AttributesList that we found or created. + return Attributes(PA); +} + +//===----------------------------------------------------------------------===// // AttributeListImpl Definition //===----------------------------------------------------------------------===// |