Revert r171427, "An intermediate step in the Attributes rewrite."

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171441 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
NAKAMURA Takumi 2013-01-03 01:42:06 +00:00
parent 3fea4ef0b4
commit 3ac03815e1
2 changed files with 23 additions and 66 deletions

View File

@ -17,7 +17,8 @@
#define LLVM_ATTRIBUTES_H #define LLVM_ATTRIBUTES_H
#include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseSet.h" #include "llvm/Support/MathExtras.h"
#include <cassert>
#include <string> #include <string>
namespace llvm { namespace llvm {
@ -151,25 +152,6 @@ public:
std::string getAsString() const; std::string getAsString() const;
}; };
//===----------------------------------------------------------------------===//
/// \class
/// \brief Provide DenseMapInfo for Attribute::AttrKind.
template<> struct DenseMapInfo<Attribute::AttrKind> {
static inline Attribute::AttrKind getEmptyKey() {
return Attribute::AttrKind(-1);
}
static inline Attribute::AttrKind getTombstoneKey() {
return Attribute::AttrKind(~0UL - 1L);
}
static unsigned getHashValue(const Attribute::AttrKind &Val) {
return (unsigned)(Val * 37UL);
}
static bool isEqual(const Attribute::AttrKind &LHS,
const Attribute::AttrKind &RHS) {
return LHS == RHS;
}
};
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
/// \class /// \class
/// \brief This class is used in conjunction with the Attribute::get method to /// \brief This class is used in conjunction with the Attribute::get method to
@ -177,64 +159,58 @@ template<> struct DenseMapInfo<Attribute::AttrKind> {
/// value, however, is not. So this can be used as a quick way to test for /// value, however, is not. So this can be used as a quick way to test for
/// equality, presence of attributes, etc. /// equality, presence of attributes, etc.
class AttrBuilder { class AttrBuilder {
DenseSet<Attribute::AttrKind> AttrSet; uint64_t Bits;
uint64_t Alignment;
uint64_t StackAlignment;
uint64_t Bits; // FIXME: Remove after encoding the attr list in the bc file.
public: public:
AttrBuilder() : Alignment(0), StackAlignment(0), Bits(0) {} AttrBuilder() : Bits(0) {}
explicit AttrBuilder(uint64_t B) : Bits(B) {} explicit AttrBuilder(uint64_t B) : Bits(B) {}
AttrBuilder(const Attribute &A) : Bits(A.getBitMask()) {} AttrBuilder(const Attribute &A) : Bits(A.getBitMask()) {}
/// \brief Clear out the builder's internals. void clear() { Bits = 0; }
void clear();
/// \brief Add an attribute to the builder. /// addAttribute - Add an attribute to the builder.
AttrBuilder &addAttribute(Attribute::AttrKind Val); AttrBuilder &addAttribute(Attribute::AttrKind Val);
/// \brief Remove an attribute from the builder. /// removeAttribute - Remove an attribute from the builder.
AttrBuilder &removeAttribute(Attribute::AttrKind Val); AttrBuilder &removeAttribute(Attribute::AttrKind Val);
/// \brief Add the attributes from A to the builder. /// addAttribute - Add the attributes from A to the builder.
AttrBuilder &addAttributes(const Attribute &A); AttrBuilder &addAttributes(const Attribute &A);
/// \brief Remove the attributes from A from the builder. /// removeAttribute - Remove the attributes from A from the builder.
AttrBuilder &removeAttributes(const Attribute &A); AttrBuilder &removeAttributes(const Attribute &A);
/// \brief Return true if the builder has the specified attribute. /// \brief Return true if the builder has the specified attribute.
bool contains(Attribute::AttrKind A) const; bool contains(Attribute::AttrKind A) const;
/// \brief Return true if the builder has IR-level attributes. /// hasAttributes - Return true if the builder has IR-level attributes.
bool hasAttributes() const; bool hasAttributes() const;
/// \brief Return true if the builder has any attribute that's in the /// hasAttributes - Return true if the builder has any attribute that's in the
/// specified attribute. /// specified attribute.
bool hasAttributes(const Attribute &A) const; bool hasAttributes(const Attribute &A) const;
/// \brief Return true if the builder has an alignment attribute. /// hasAlignmentAttr - Return true if the builder has an alignment attribute.
bool hasAlignmentAttr() const; bool hasAlignmentAttr() const;
/// \brief Retrieve the alignment attribute, if it exists. /// getAlignment - Retrieve the alignment attribute, if it exists.
uint64_t getAlignment() const; uint64_t getAlignment() const;
/// \brief Retrieve the stack alignment attribute, if it exists. /// getStackAlignment - Retrieve the stack alignment attribute, if it exists.
uint64_t getStackAlignment() const; uint64_t getStackAlignment() const;
/// \brief This turns an int alignment (which must be a power of 2) into the /// addAlignmentAttr - This turns an int alignment (which must be a power of
/// form used internally in Attribute. /// 2) into the form used internally in Attribute.
AttrBuilder &addAlignmentAttr(unsigned Align); AttrBuilder &addAlignmentAttr(unsigned Align);
/// \brief This turns an int stack alignment (which must be a power of 2) into /// addStackAlignmentAttr - This turns an int stack alignment (which must be a
/// the form used internally in Attribute. /// power of 2) into the form used internally in Attribute.
AttrBuilder &addStackAlignmentAttr(unsigned Align); AttrBuilder &addStackAlignmentAttr(unsigned Align);
/// \brief Add the raw value to the internal representation. /// addRawValue - Add the raw value to the internal representation.
///
/// N.B. This should be used ONLY for decoding LLVM bitcode! /// N.B. This should be used ONLY for decoding LLVM bitcode!
AttrBuilder &addRawValue(uint64_t Val); AttrBuilder &addRawValue(uint64_t Val);
/// \brief Remove attributes that are used on functions only. /// @brief Remove attributes that are used on functions only.
void removeFunctionOnlyAttrs() { void removeFunctionOnlyAttrs() {
removeAttribute(Attribute::NoReturn) removeAttribute(Attribute::NoReturn)
.removeAttribute(Attribute::NoUnwind) .removeAttribute(Attribute::NoUnwind)
@ -260,10 +236,10 @@ public:
uint64_t getBitMask() const { return Bits; } uint64_t getBitMask() const { return Bits; }
bool operator==(const AttrBuilder &B) const { bool operator==(const AttrBuilder &B) {
return Bits == B.Bits; return Bits == B.Bits;
} }
bool operator!=(const AttrBuilder &B) const { bool operator!=(const AttrBuilder &B) {
return Bits != B.Bits; return Bits != B.Bits;
} }
}; };

View File

@ -233,15 +233,8 @@ std::string Attribute::getAsString() const {
// AttrBuilder Implementation // AttrBuilder Implementation
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
void AttrBuilder::clear() {
AttrSet.clear();
Alignment = StackAlignment = Bits = 0;
}
AttrBuilder &AttrBuilder::addAttribute(Attribute::AttrKind Val){ AttrBuilder &AttrBuilder::addAttribute(Attribute::AttrKind Val){
Bits |= AttributeImpl::getAttrMask(Val); Bits |= AttributeImpl::getAttrMask(Val);
AttrSet.insert(Val);
return *this; return *this;
} }
@ -255,31 +248,19 @@ AttrBuilder &AttrBuilder::addAlignmentAttr(unsigned Align) {
assert(isPowerOf2_32(Align) && "Alignment must be a power of two."); assert(isPowerOf2_32(Align) && "Alignment must be a power of two.");
assert(Align <= 0x40000000 && "Alignment too large."); assert(Align <= 0x40000000 && "Alignment too large.");
Bits |= (Log2_32(Align) + 1) << 16; Bits |= (Log2_32(Align) + 1) << 16;
AttrSet.insert(Attribute::Alignment);
Alignment = Align;
return *this; return *this;
} }
AttrBuilder &AttrBuilder::addStackAlignmentAttr(unsigned Align) { AttrBuilder &AttrBuilder::addStackAlignmentAttr(unsigned Align){
// Default alignment, allow the target to define how to align it. // Default alignment, allow the target to define how to align it.
if (Align == 0) return *this; if (Align == 0) return *this;
assert(isPowerOf2_32(Align) && "Alignment must be a power of two."); assert(isPowerOf2_32(Align) && "Alignment must be a power of two.");
assert(Align <= 0x100 && "Alignment too large."); assert(Align <= 0x100 && "Alignment too large.");
Bits |= (Log2_32(Align) + 1) << 26; Bits |= (Log2_32(Align) + 1) << 26;
AttrSet.insert(Attribute::StackAlignment);
StackAlignment = Align;
return *this; return *this;
} }
AttrBuilder &AttrBuilder::removeAttribute(Attribute::AttrKind Val) { AttrBuilder &AttrBuilder::removeAttribute(Attribute::AttrKind Val) {
Bits &= ~AttributeImpl::getAttrMask(Val); Bits &= ~AttributeImpl::getAttrMask(Val);
AttrSet.erase(Val);
if (Val == Attribute::Alignment)
Alignment = 0;
else if (Val == Attribute::StackAlignment)
StackAlignment = 0;
return *this; return *this;
} }