mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-23 02:29:18 +00:00
Futureproof AttrBuild if we ever have more than 64 attr enum values.
Currently we're at 34. Bitset should compile into virtually the same code as uint64_t here. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@175437 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
32d0b2a9e8
commit
3f213e7b3a
@ -19,6 +19,7 @@
|
|||||||
#include "llvm/ADT/ArrayRef.h"
|
#include "llvm/ADT/ArrayRef.h"
|
||||||
#include "llvm/ADT/FoldingSet.h"
|
#include "llvm/ADT/FoldingSet.h"
|
||||||
#include "llvm/Support/PointerLikeTypeTraits.h"
|
#include "llvm/Support/PointerLikeTypeTraits.h"
|
||||||
|
#include <bitset>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -378,7 +379,7 @@ template<> struct DenseMapInfo<AttributeSet> {
|
|||||||
/// 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 {
|
||||||
uint64_t Attrs;
|
std::bitset<Attribute::EndAttrKinds> Attrs;
|
||||||
std::map<std::string, std::string> TargetDepAttrs;
|
std::map<std::string, std::string> TargetDepAttrs;
|
||||||
uint64_t Alignment;
|
uint64_t Alignment;
|
||||||
uint64_t StackAlignment;
|
uint64_t StackAlignment;
|
||||||
@ -422,9 +423,8 @@ public:
|
|||||||
|
|
||||||
/// \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 {
|
||||||
assert((unsigned)A < 64 && A < Attribute::EndAttrKinds &&
|
assert((unsigned)A < Attribute::EndAttrKinds && "Attribute out of range!");
|
||||||
"Attribute out of range!");
|
return Attrs[A];
|
||||||
return Attrs & (1ULL << A);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \brief Return true if the builder has the specified target-dependent
|
/// \brief Return true if the builder has the specified target-dependent
|
||||||
@ -457,7 +457,7 @@ public:
|
|||||||
|
|
||||||
/// \brief Return true if the builder contains no target-independent
|
/// \brief Return true if the builder contains no target-independent
|
||||||
/// attributes.
|
/// attributes.
|
||||||
bool empty() const { return Attrs == 0; }
|
bool empty() const { return Attrs.none(); }
|
||||||
|
|
||||||
// Iterators for target-dependent attributes.
|
// Iterators for target-dependent attributes.
|
||||||
typedef std::pair<std::string, std::string> td_type;
|
typedef std::pair<std::string, std::string> td_type;
|
||||||
|
@ -924,16 +924,15 @@ AttrBuilder::AttrBuilder(AttributeSet AS, unsigned Idx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AttrBuilder::clear() {
|
void AttrBuilder::clear() {
|
||||||
Attrs = 0;
|
Attrs.reset();
|
||||||
Alignment = StackAlignment = 0;
|
Alignment = StackAlignment = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
AttrBuilder &AttrBuilder::addAttribute(Attribute::AttrKind Val) {
|
AttrBuilder &AttrBuilder::addAttribute(Attribute::AttrKind Val) {
|
||||||
assert((unsigned)Val < 64 && Val < Attribute::EndAttrKinds &&
|
assert((unsigned)Val < Attribute::EndAttrKinds && "Attribute out of range!");
|
||||||
"Attribute out of range!");
|
|
||||||
assert(Val != Attribute::Alignment && Val != Attribute::StackAlignment &&
|
assert(Val != Attribute::Alignment && Val != Attribute::StackAlignment &&
|
||||||
"Adding alignment attribute without adding alignment value!");
|
"Adding alignment attribute without adding alignment value!");
|
||||||
Attrs |= 1ULL << Val;
|
Attrs[Val] = true;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -944,7 +943,7 @@ AttrBuilder &AttrBuilder::addAttribute(Attribute Attr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Attribute::AttrKind Kind = Attr.getKindAsEnum();
|
Attribute::AttrKind Kind = Attr.getKindAsEnum();
|
||||||
Attrs |= 1ULL << Kind;
|
Attrs[Kind] = true;
|
||||||
|
|
||||||
if (Kind == Attribute::Alignment)
|
if (Kind == Attribute::Alignment)
|
||||||
Alignment = Attr.getAlignment();
|
Alignment = Attr.getAlignment();
|
||||||
@ -959,9 +958,8 @@ AttrBuilder &AttrBuilder::addAttribute(StringRef A, StringRef V) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
AttrBuilder &AttrBuilder::removeAttribute(Attribute::AttrKind Val) {
|
AttrBuilder &AttrBuilder::removeAttribute(Attribute::AttrKind Val) {
|
||||||
assert((unsigned)Val < 64 && Val < Attribute::EndAttrKinds &&
|
assert((unsigned)Val < Attribute::EndAttrKinds && "Attribute out of range!");
|
||||||
"Attribute out of range!");
|
Attrs[Val] = false;
|
||||||
Attrs &= ~(1ULL << Val);
|
|
||||||
|
|
||||||
if (Val == Attribute::Alignment)
|
if (Val == Attribute::Alignment)
|
||||||
Alignment = 0;
|
Alignment = 0;
|
||||||
@ -985,7 +983,7 @@ AttrBuilder &AttrBuilder::removeAttributes(AttributeSet A, uint64_t Index) {
|
|||||||
Attribute Attr = *I;
|
Attribute Attr = *I;
|
||||||
if (Attr.isEnumAttribute() || Attr.isAlignAttribute()) {
|
if (Attr.isEnumAttribute() || Attr.isAlignAttribute()) {
|
||||||
Attribute::AttrKind Kind = I->getKindAsEnum();
|
Attribute::AttrKind Kind = I->getKindAsEnum();
|
||||||
Attrs &= ~(1ULL << Kind);
|
Attrs[Kind] = false;
|
||||||
|
|
||||||
if (Kind == Attribute::Alignment)
|
if (Kind == Attribute::Alignment)
|
||||||
Alignment = 0;
|
Alignment = 0;
|
||||||
@ -1016,7 +1014,7 @@ 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.");
|
||||||
|
|
||||||
Attrs |= 1ULL << Attribute::Alignment;
|
Attrs[Attribute::Alignment] = true;
|
||||||
Alignment = Align;
|
Alignment = Align;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@ -1028,7 +1026,7 @@ AttrBuilder &AttrBuilder::addStackAlignmentAttr(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 <= 0x100 && "Alignment too large.");
|
assert(Align <= 0x100 && "Alignment too large.");
|
||||||
|
|
||||||
Attrs |= 1ULL << Attribute::StackAlignment;
|
Attrs[Attribute::StackAlignment] = true;
|
||||||
StackAlignment = Align;
|
StackAlignment = Align;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@ -1055,7 +1053,7 @@ bool AttrBuilder::contains(StringRef A) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool AttrBuilder::hasAttributes() const {
|
bool AttrBuilder::hasAttributes() const {
|
||||||
return Attrs != 0 || !TargetDepAttrs.empty();
|
return !Attrs.none() || !TargetDepAttrs.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AttrBuilder::hasAttributes(AttributeSet A, uint64_t Index) const {
|
bool AttrBuilder::hasAttributes(AttributeSet A, uint64_t Index) const {
|
||||||
@ -1072,7 +1070,7 @@ bool AttrBuilder::hasAttributes(AttributeSet A, uint64_t Index) const {
|
|||||||
I != E; ++I) {
|
I != E; ++I) {
|
||||||
Attribute Attr = *I;
|
Attribute Attr = *I;
|
||||||
if (Attr.isEnumAttribute() || Attr.isAlignAttribute()) {
|
if (Attr.isEnumAttribute() || Attr.isAlignAttribute()) {
|
||||||
if (Attrs & (1ULL << I->getKindAsEnum()))
|
if (Attrs[I->getKindAsEnum()])
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
assert(Attr.isStringAttribute() && "Invalid attribute kind!");
|
assert(Attr.isStringAttribute() && "Invalid attribute kind!");
|
||||||
@ -1106,7 +1104,7 @@ AttrBuilder &AttrBuilder::addRawValue(uint64_t Val) {
|
|||||||
for (Attribute::AttrKind I = Attribute::None; I != Attribute::EndAttrKinds;
|
for (Attribute::AttrKind I = Attribute::None; I != Attribute::EndAttrKinds;
|
||||||
I = Attribute::AttrKind(I + 1)) {
|
I = Attribute::AttrKind(I + 1)) {
|
||||||
if (uint64_t A = (Val & AttributeImpl::getAttrMask(I))) {
|
if (uint64_t A = (Val & AttributeImpl::getAttrMask(I))) {
|
||||||
Attrs |= 1ULL << I;
|
Attrs[I] = true;
|
||||||
|
|
||||||
if (I == Attribute::Alignment)
|
if (I == Attribute::Alignment)
|
||||||
Alignment = 1ULL << ((A >> 16) - 1);
|
Alignment = 1ULL << ((A >> 16) - 1);
|
||||||
|
Loading…
Reference in New Issue
Block a user