From: Bill Wendling Date: Mon, 8 Oct 2012 21:47:17 +0000 (+0000) Subject: Begin the transition to using the AttributesImpl object for the Attributes ivar. X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=commitdiff_plain;h=8e635dbc78996bc18cf13b4806706cf3529ea646 Begin the transition to using the AttributesImpl object for the Attributes ivar. Start using the AttributesImpl object to hold the value of the attributes. All queries go through the interfaces now. This has one unfortunate consequence. I needed to move the AttributesImpl.h file into include/llvm. But this is only temporary! Otherwise, the changes needed to support this would be too large. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@165433 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Attributes.h b/include/llvm/Attributes.h index 6f250285bb2..fc666c71c38 100644 --- a/include/llvm/Attributes.h +++ b/include/llvm/Attributes.h @@ -15,6 +15,7 @@ #ifndef LLVM_ATTRIBUTES_H #define LLVM_ATTRIBUTES_H +#include "llvm/AttributesImpl.h" #include "llvm/Support/MathExtras.h" #include "llvm/ADT/ArrayRef.h" #include @@ -142,20 +143,20 @@ class AttributesImpl; /// Attributes - A bitset of attributes. class Attributes { // Currently, we need less than 64 bits. - uint64_t Bits; + AttributesImpl Attrs; explicit Attributes(AttributesImpl *A); public: - Attributes() : Bits(0) {} - explicit Attributes(uint64_t Val) : Bits(Val) {} - /*implicit*/ Attributes(Attribute::AttrConst Val) : Bits(Val.v) {} + Attributes() : Attrs(0) {} + explicit Attributes(uint64_t Val); + /*implicit*/ Attributes(Attribute::AttrConst Val); class Builder { friend class Attributes; uint64_t Bits; public: Builder() : Bits(0) {} - Builder(const Attributes &A) : Bits(A.Bits) {} + Builder(const Attributes &A) : Bits(A.Raw()) {} void addAddressSafetyAttr(); void addAlwaysInlineAttr(); @@ -185,6 +186,32 @@ public: void addAlignmentAttr(unsigned Align); void addStackAlignmentAttr(unsigned Align); + + void removeAddressSafetyAttr(); + void removeAlwaysInlineAttr(); + void removeByValAttr(); + void removeInlineHintAttr(); + void removeInRegAttr(); + void removeNakedAttr(); + void removeNestAttr(); + void removeNoAliasAttr(); + void removeNoCaptureAttr(); + void removeNoImplicitFloatAttr(); + void removeNoInlineAttr(); + void removeNonLazyBindAttr(); + void removeNoRedZoneAttr(); + void removeNoReturnAttr(); + void removeNoUnwindAttr(); + void removeOptimizeForSizeAttr(); + void removeReadNoneAttr(); + void removeReadOnlyAttr(); + void removeReturnsTwiceAttr(); + void removeSExtAttr(); + void removeStackProtectAttr(); + void removeStackProtectReqAttr(); + void removeStructRetAttr(); + void removeUWTableAttr(); + void removeZExtAttr(); }; /// get - Return a uniquified Attributes object. This takes the uniquified @@ -194,7 +221,7 @@ public: // Attribute query methods. // FIXME: StackAlignment & Alignment attributes have no predicate methods. bool hasAttributes() const { - return Bits != 0; + return Attrs.hasAttributes(); } bool hasAttributes(const Attributes &A) const; bool hasAddressSafetyAttr() const; @@ -236,22 +263,22 @@ public: bool isEmptyOrSingleton() const; // This is a "safe bool() operator". - operator const void *() const { return Bits ? this : 0; } - bool operator == (const Attributes &Attrs) const { - return Bits == Attrs.Bits; + operator const void *() const { return Attrs.Bits ? this : 0; } + bool operator == (const Attributes &A) const { + return Attrs.Bits == A.Attrs.Bits; } - bool operator != (const Attributes &Attrs) const { - return Bits != Attrs.Bits; + bool operator != (const Attributes &A) const { + return Attrs.Bits != A.Attrs.Bits; } - Attributes operator | (const Attributes &Attrs) const; - Attributes operator & (const Attributes &Attrs) const; - Attributes operator ^ (const Attributes &Attrs) const; - Attributes &operator |= (const Attributes &Attrs); - Attributes &operator &= (const Attributes &Attrs); + Attributes operator | (const Attributes &A) const; + Attributes operator & (const Attributes &A) const; + Attributes operator ^ (const Attributes &A) const; + Attributes &operator |= (const Attributes &A); + Attributes &operator &= (const Attributes &A); Attributes operator ~ () const; - uint64_t Raw() const { return Bits; } + uint64_t Raw() const; /// constructAlignmentFromInt - This turns an int alignment (a power of 2, /// normally) into the form used internally in Attributes. diff --git a/include/llvm/AttributesImpl.h b/include/llvm/AttributesImpl.h new file mode 100644 index 00000000000..26e873bd834 --- /dev/null +++ b/include/llvm/AttributesImpl.h @@ -0,0 +1,50 @@ +//===-- AttributesImpl.h - Attributes Internals -----------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file defines various helper methods and classes used by LLVMContextImpl +// for creating and managing attributes. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_ATTRIBUTESIMPL_H +#define LLVM_ATTRIBUTESIMPL_H + +#include "llvm/ADT/FoldingSet.h" + +namespace llvm { + +class Attributes; + +class AttributesImpl : public FoldingSetNode { + friend class Attributes; + + uint64_t Bits; // FIXME: We will be expanding this. +public: + AttributesImpl(uint64_t bits) : Bits(bits) {} + + bool hasAttribute(uint64_t A) const; + bool hasAttributes() const; + bool hasAttributes(const Attributes &A) const; + + uint64_t getAlignment() const; + uint64_t getStackAlignment() const; + + bool isEmptyOrSingleton() const; + + void Profile(FoldingSetNodeID &ID) const { + Profile(ID, Bits); + } + static void Profile(FoldingSetNodeID &ID, uint64_t Bits) { + ID.AddInteger(Bits); + } +}; + +} // end llvm namespace + +#endif diff --git a/lib/VMCore/Attributes.cpp b/lib/VMCore/Attributes.cpp index d1b693b4c68..e20fa6b4327 100644 --- a/lib/VMCore/Attributes.cpp +++ b/lib/VMCore/Attributes.cpp @@ -12,7 +12,6 @@ //===----------------------------------------------------------------------===// #include "llvm/Attributes.h" -#include "AttributesImpl.h" #include "LLVMContextImpl.h" #include "llvm/Type.h" #include "llvm/ADT/StringExtras.h" @@ -25,99 +24,129 @@ using namespace llvm; //===----------------------------------------------------------------------===// -// Attribute Function Definitions +// Attributes Implementation //===----------------------------------------------------------------------===// +Attributes::Attributes(uint64_t Val) : Attrs(Val) {} + +Attributes::Attributes(Attribute::AttrConst Val) : Attrs(Val.v) {} + +Attributes::Attributes(AttributesImpl *A) : Attrs(A->Bits) {} + +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); +} + bool Attributes::hasAttributes(const Attributes &A) const { - return Bits & A.Bits; + return Attrs.hasAttributes(A); } bool Attributes::hasAddressSafetyAttr() const { - return Bits & Attribute::AddressSafety_i; + return Attrs.hasAttribute(Attribute::AddressSafety_i); } bool Attributes::hasAlignmentAttr() const { - return Bits & Attribute::Alignment_i; + return Attrs.hasAttribute(Attribute::Alignment_i); } bool Attributes::hasAlwaysInlineAttr() const { - return Bits & Attribute::AlwaysInline_i; + return Attrs.hasAttribute(Attribute::AlwaysInline_i); } bool Attributes::hasByValAttr() const { - return Bits & Attribute::ByVal_i; + return Attrs.hasAttribute(Attribute::ByVal_i); } bool Attributes::hasInlineHintAttr() const { - return Bits & Attribute::InlineHint_i; + return Attrs.hasAttribute(Attribute::InlineHint_i); } bool Attributes::hasInRegAttr() const { - return Bits & Attribute::InReg_i; + return Attrs.hasAttribute(Attribute::InReg_i); } bool Attributes::hasNakedAttr() const { - return Bits & Attribute::Naked_i; + return Attrs.hasAttribute(Attribute::Naked_i); } bool Attributes::hasNestAttr() const { - return Bits & Attribute::Nest_i; + return Attrs.hasAttribute(Attribute::Nest_i); } bool Attributes::hasNoAliasAttr() const { - return Bits & Attribute::NoAlias_i; + return Attrs.hasAttribute(Attribute::NoAlias_i); } bool Attributes::hasNoCaptureAttr() const { - return Bits & Attribute::NoCapture_i; + return Attrs.hasAttribute(Attribute::NoCapture_i); } bool Attributes::hasNoImplicitFloatAttr() const { - return Bits & Attribute::NoImplicitFloat_i; + return Attrs.hasAttribute(Attribute::NoImplicitFloat_i); } bool Attributes::hasNoInlineAttr() const { - return Bits & Attribute::NoInline_i; + return Attrs.hasAttribute(Attribute::NoInline_i); } bool Attributes::hasNonLazyBindAttr() const { - return Bits & Attribute::NonLazyBind_i; + return Attrs.hasAttribute(Attribute::NonLazyBind_i); } bool Attributes::hasNoRedZoneAttr() const { - return Bits & Attribute::NoRedZone_i; + return Attrs.hasAttribute(Attribute::NoRedZone_i); } bool Attributes::hasNoReturnAttr() const { - return Bits & Attribute::NoReturn_i; + return Attrs.hasAttribute(Attribute::NoReturn_i); } bool Attributes::hasNoUnwindAttr() const { - return Bits & Attribute::NoUnwind_i; + return Attrs.hasAttribute(Attribute::NoUnwind_i); } bool Attributes::hasOptimizeForSizeAttr() const { - return Bits & Attribute::OptimizeForSize_i; + return Attrs.hasAttribute(Attribute::OptimizeForSize_i); } bool Attributes::hasReadNoneAttr() const { - return Bits & Attribute::ReadNone_i; + return Attrs.hasAttribute(Attribute::ReadNone_i); } bool Attributes::hasReadOnlyAttr() const { - return Bits & Attribute::ReadOnly_i; + return Attrs.hasAttribute(Attribute::ReadOnly_i); } bool Attributes::hasReturnsTwiceAttr() const { - return Bits & Attribute::ReturnsTwice_i; + return Attrs.hasAttribute(Attribute::ReturnsTwice_i); } bool Attributes::hasSExtAttr() const { - return Bits & Attribute::SExt_i; + return Attrs.hasAttribute(Attribute::SExt_i); } bool Attributes::hasStackAlignmentAttr() const { - return Bits & Attribute::StackAlignment_i; + return Attrs.hasAttribute(Attribute::StackAlignment_i); } bool Attributes::hasStackProtectAttr() const { - return Bits & Attribute::StackProtect_i; + return Attrs.hasAttribute(Attribute::StackProtect_i); } bool Attributes::hasStackProtectReqAttr() const { - return Bits & Attribute::StackProtectReq_i; + return Attrs.hasAttribute(Attribute::StackProtectReq_i); } bool Attributes::hasStructRetAttr() const { - return Bits & Attribute::StructRet_i; + return Attrs.hasAttribute(Attribute::StructRet_i); } bool Attributes::hasUWTableAttr() const { - return Bits & Attribute::UWTable_i; + return Attrs.hasAttribute(Attribute::UWTable_i); } bool Attributes::hasZExtAttr() const { - return Bits & Attribute::ZExt_i; + return Attrs.hasAttribute(Attribute::ZExt_i); } /// This returns the alignment field of an attribute as a byte alignment value. unsigned Attributes::getAlignment() const { if (!hasAlignmentAttr()) return 0; - return 1U << (((Bits & Attribute::Alignment_i) >> 16) - 1); + return 1U << ((Attrs.getAlignment() >> 16) - 1); } /// This returns the stack alignment field of an attribute as a byte alignment @@ -125,32 +154,36 @@ unsigned Attributes::getAlignment() const { unsigned Attributes::getStackAlignment() const { if (!hasStackAlignmentAttr()) return 0; - return 1U << (((Bits & Attribute::StackAlignment_i) >> 26) - 1); + return 1U << ((Attrs.getStackAlignment() >> 26) - 1); } bool Attributes::isEmptyOrSingleton() const { - return (Bits & (Bits - 1)) == 0; + return Attrs.isEmptyOrSingleton(); } -Attributes Attributes::operator | (const Attributes &Attrs) const { - return Attributes(Bits | Attrs.Bits); +Attributes Attributes::operator | (const Attributes &A) const { + return Attributes(Raw() | A.Raw()); } -Attributes Attributes::operator & (const Attributes &Attrs) const { - return Attributes(Bits & Attrs.Bits); +Attributes Attributes::operator & (const Attributes &A) const { + return Attributes(Raw() & A.Raw()); } -Attributes Attributes::operator ^ (const Attributes &Attrs) const { - return Attributes(Bits ^ Attrs.Bits); +Attributes Attributes::operator ^ (const Attributes &A) const { + return Attributes(Raw() ^ A.Raw()); } -Attributes &Attributes::operator |= (const Attributes &Attrs) { - Bits |= Attrs.Bits; +Attributes &Attributes::operator |= (const Attributes &A) { + Attrs.Bits |= A.Raw(); return *this; } -Attributes &Attributes::operator &= (const Attributes &Attrs) { - Bits &= Attrs.Bits; +Attributes &Attributes::operator &= (const Attributes &A) { + Attrs.Bits &= A.Raw(); return *this; } Attributes Attributes::operator ~ () const { - return Attributes(~Bits); + return Attributes(~Raw()); +} + +uint64_t Attributes::Raw() const { + return Attrs.Bits; } Attributes Attributes::typeIncompatible(Type *Ty) { @@ -336,34 +369,108 @@ void Attributes::Builder::addStackAlignmentAttr(unsigned Align) { Bits |= (Log2_32(Align) + 1) << 26; } +void Attributes::Builder::removeAddressSafetyAttr() { + Bits &= ~Attribute::AddressSafety_i; +} +void Attributes::Builder::removeAlwaysInlineAttr() { + Bits &= ~Attribute::AlwaysInline_i; +} +void Attributes::Builder::removeByValAttr() { + Bits &= ~Attribute::ByVal_i; +} +void Attributes::Builder::removeInlineHintAttr() { + Bits &= ~Attribute::InlineHint_i; +} +void Attributes::Builder::removeInRegAttr() { + Bits &= ~Attribute::InReg_i; +} +void Attributes::Builder::removeNakedAttr() { + Bits &= ~Attribute::Naked_i; +} +void Attributes::Builder::removeNestAttr() { + Bits &= ~Attribute::Nest_i; +} +void Attributes::Builder::removeNoAliasAttr() { + Bits &= ~Attribute::NoAlias_i; +} +void Attributes::Builder::removeNoCaptureAttr() { + Bits &= ~Attribute::NoCapture_i; +} +void Attributes::Builder::removeNoImplicitFloatAttr() { + Bits &= ~Attribute::NoImplicitFloat_i; +} +void Attributes::Builder::removeNoInlineAttr() { + Bits &= ~Attribute::NoInline_i; +} +void Attributes::Builder::removeNonLazyBindAttr() { + Bits &= ~Attribute::NonLazyBind_i; +} +void Attributes::Builder::removeNoRedZoneAttr() { + Bits &= ~Attribute::NoRedZone_i; +} +void Attributes::Builder::removeNoReturnAttr() { + Bits &= ~Attribute::NoReturn_i; +} +void Attributes::Builder::removeNoUnwindAttr() { + Bits &= ~Attribute::NoUnwind_i; +} +void Attributes::Builder::removeOptimizeForSizeAttr() { + Bits &= ~Attribute::OptimizeForSize_i; +} +void Attributes::Builder::removeReadNoneAttr() { + Bits &= ~Attribute::ReadNone_i; +} +void Attributes::Builder::removeReadOnlyAttr() { + Bits &= ~Attribute::ReadOnly_i; +} +void Attributes::Builder::removeReturnsTwiceAttr() { + Bits &= ~Attribute::ReturnsTwice_i; +} +void Attributes::Builder::removeSExtAttr() { + Bits &= ~Attribute::SExt_i; +} +void Attributes::Builder::removeStackProtectAttr() { + Bits &= ~Attribute::StackProtect_i; +} +void Attributes::Builder::removeStackProtectReqAttr() { + Bits &= ~Attribute::StackProtectReq_i; +} +void Attributes::Builder::removeStructRetAttr() { + Bits &= ~Attribute::StructRet_i; +} +void Attributes::Builder::removeUWTableAttr() { + Bits &= ~Attribute::UWTable_i; +} +void Attributes::Builder::removeZExtAttr() { + Bits &= ~Attribute::ZExt_i; +} + //===----------------------------------------------------------------------===// // AttributeImpl Definition //===----------------------------------------------------------------------===// -Attributes::Attributes(AttributesImpl *A) : Bits(0) {} +bool AttributesImpl::hasAttribute(uint64_t A) const { + return (Bits & A) != 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(); +bool AttributesImpl::hasAttributes() const { + return Bits != 0; +} - // Otherwise, build a key to look up the existing attributes. - LLVMContextImpl *pImpl = Context.pImpl; - FoldingSetNodeID ID; - ID.AddInteger(B.Bits); +bool AttributesImpl::hasAttributes(const Attributes &A) const { + return Bits & A.Raw(); // FIXME: Raw() won't work here in the future. +} - void *InsertPoint; - AttributesImpl *PA = pImpl->AttrsSet.FindNodeOrInsertPos(ID, InsertPoint); +uint64_t AttributesImpl::getAlignment() const { + return Bits & Attribute::Alignment_i; +} - 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); - } +uint64_t AttributesImpl::getStackAlignment() const { + return Bits & Attribute::StackAlignment_i; +} - // Return the AttributesList that we found or created. - return Attributes(PA); +bool AttributesImpl::isEmptyOrSingleton() const { + return (Bits & (Bits - 1)) == 0; } //===----------------------------------------------------------------------===// diff --git a/lib/VMCore/AttributesImpl.h b/lib/VMCore/AttributesImpl.h deleted file mode 100644 index 90890a14c3f..00000000000 --- a/lib/VMCore/AttributesImpl.h +++ /dev/null @@ -1,40 +0,0 @@ -//===-- AttributesImpl.h - Attributes Internals -----------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file defines various helper methods and classes used by LLVMContextImpl -// for creating and managing attributes. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_ATTRIBUTESIMPL_H -#define LLVM_ATTRIBUTESIMPL_H - -#include "llvm/ADT/FoldingSet.h" - -namespace llvm { - -class AttributesImpl : public FoldingSetNode { - uint64_t Bits; // FIXME: We will be expanding this. - - void operator=(const AttributesImpl &) LLVM_DELETED_FUNCTION; - AttributesImpl(const AttributesImpl &) LLVM_DELETED_FUNCTION; -public: - AttributesImpl(uint64_t bits) : Bits(bits) {} - - void Profile(FoldingSetNodeID &ID) const { - Profile(ID, Bits); - } - static void Profile(FoldingSetNodeID &ID, uint64_t Bits) { - ID.AddInteger(Bits); - } -}; - -} // end llvm namespace - -#endif diff --git a/lib/VMCore/LLVMContextImpl.h b/lib/VMCore/LLVMContextImpl.h index ee31814c055..524f7e54bb4 100644 --- a/lib/VMCore/LLVMContextImpl.h +++ b/lib/VMCore/LLVMContextImpl.h @@ -16,9 +16,9 @@ #define LLVM_LLVMCONTEXT_IMPL_H #include "llvm/LLVMContext.h" -#include "AttributesImpl.h" #include "ConstantsContext.h" #include "LeaksContext.h" +#include "llvm/AttributesImpl.h" #include "llvm/Constants.h" #include "llvm/DerivedTypes.h" #include "llvm/Metadata.h"