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 6f25028..fc666c7 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 <cassert>
@@ -142,20 +143,20 @@
/// 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 @@
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 @@
// 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 @@
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/lib/VMCore/AttributesImpl.h b/include/llvm/AttributesImpl.h
similarity index 78%
rename from lib/VMCore/AttributesImpl.h
rename to include/llvm/AttributesImpl.h
index 90890a1..26e873b 100644
--- a/lib/VMCore/AttributesImpl.h
+++ b/include/llvm/AttributesImpl.h
@@ -19,14 +19,24 @@
namespace llvm {
-class AttributesImpl : public FoldingSetNode {
- uint64_t Bits; // FIXME: We will be expanding this.
+class Attributes;
- void operator=(const AttributesImpl &) LLVM_DELETED_FUNCTION;
- AttributesImpl(const AttributesImpl &) LLVM_DELETED_FUNCTION;
+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);
}
diff --git a/lib/VMCore/Attributes.cpp b/lib/VMCore/Attributes.cpp
index d1b693b..e20fa6b 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::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 @@
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/LLVMContextImpl.h b/lib/VMCore/LLVMContextImpl.h
index ee31814..524f7e5 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"