aboutsummaryrefslogtreecommitdiff
path: root/lib/IR/AttributeImpl.h
diff options
context:
space:
mode:
authorMatthias Braun <matze@braunis.de>2016-01-29 22:25:13 +0000
committerMatthias Braun <matze@braunis.de>2016-01-29 22:25:13 +0000
commita5c14e44924b512d02191d6726a5a736655c206b (patch)
treed8e7d4c3f442c94f0fe76b150f0965aed63b1a82 /lib/IR/AttributeImpl.h
parent1626c62205ac0b05e59595395ccb7800d9cdb1d2 (diff)
AttributeSetNode: Summarize existing attributes in a bitset.
The majority of queries just checks for the existince of an enum attribute. We only have 48 of those and can summaryiz them in an uint64_t bitfield so we can avoid searching the list. This improves "opt" compile time by 1-4% in my measurements. Differential Revision: http://reviews.llvm.org/D16617 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@259251 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/IR/AttributeImpl.h')
-rw-r--r--lib/IR/AttributeImpl.h17
1 files changed, 15 insertions, 2 deletions
diff --git a/lib/IR/AttributeImpl.h b/lib/IR/AttributeImpl.h
index 659f9568b7c..59d09c3d406 100644
--- a/lib/IR/AttributeImpl.h
+++ b/lib/IR/AttributeImpl.h
@@ -148,10 +148,21 @@ class AttributeSetNode final
friend TrailingObjects;
unsigned NumAttrs; ///< Number of attributes in this node.
+ /// Bitset with a bit for each available attribute Attribute::AttrKind.
+ uint64_t AvailableAttrs;
+ static_assert(Attribute::EndAttrKinds <= sizeof(AvailableAttrs)*CHAR_BIT,
+ "Too many attributes for AvailableAttrs");
- AttributeSetNode(ArrayRef<Attribute> Attrs) : NumAttrs(Attrs.size()) {
+ AttributeSetNode(ArrayRef<Attribute> Attrs)
+ : NumAttrs(Attrs.size()), AvailableAttrs(0) {
// There's memory after the node where we can store the entries in.
std::copy(Attrs.begin(), Attrs.end(), getTrailingObjects<Attribute>());
+
+ for (iterator I = begin(), E = end(); I != E; ++I) {
+ if (!I->isStringAttribute()) {
+ AvailableAttrs |= ((uint64_t)1) << I->getKindAsEnum();
+ }
+ }
}
// AttributesSetNode is uniqued, these should not be publicly available.
@@ -160,7 +171,9 @@ class AttributeSetNode final
public:
static AttributeSetNode *get(LLVMContext &C, ArrayRef<Attribute> Attrs);
- bool hasAttribute(Attribute::AttrKind Kind) const;
+ bool hasAttribute(Attribute::AttrKind Kind) const {
+ return AvailableAttrs & ((uint64_t)1) << Kind;
+ }
bool hasAttribute(StringRef Kind) const;
bool hasAttributes() const { return NumAttrs != 0; }