#define LLVM_LIB_IR_ATTRIBUTEIMPL_H
#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/FoldingSet.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/IR/Attributes.h"
/// Bitset with a bit for each available attribute Attribute::AttrKind.
uint8_t AvailableAttrs[12] = {};
+ DenseMap<StringRef, Attribute> StringAttrs;
+
AttributeSetNode(ArrayRef<Attribute> Attrs);
public:
"Too many attributes");
for (const auto &I : *this) {
- if (!I.isStringAttribute()) {
+ if (I.isStringAttribute()) {
+ StringAttrs.insert({ I.getKindAsString(), I });
+ } else {
Attribute::AttrKind Kind = I.getKindAsEnum();
AvailableAttrs[Kind / 8] |= 1ULL << (Kind % 8);
}
}
bool AttributeSetNode::hasAttribute(StringRef Kind) const {
- for (const auto &I : *this)
- if (I.hasAttribute(Kind))
- return true;
- return false;
+ return StringAttrs.count(Kind);
}
Attribute AttributeSetNode::getAttribute(Attribute::AttrKind Kind) const {
}
Attribute AttributeSetNode::getAttribute(StringRef Kind) const {
- for (const auto &I : *this)
- if (I.hasAttribute(Kind))
- return I;
- return {};
+ return StringAttrs.lookup(Kind);
}
MaybeAlign AttributeSetNode::getAlignment() const {