summaryrefslogtreecommitdiffstats
path: root/llvm/lib/IR
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
commit31eeb76f5e3b73f2eb5364ee840789c74723eb1b (patch)
tree0a670e07492b29a16677c741189589a143fc97b6 /llvm/lib/IR
parent5e378ddc1e0396e1296f934d8b1da7ce108d67b6 (diff)
downloadbcm5719-llvm-31eeb76f5e3b73f2eb5364ee840789c74723eb1b.tar.gz
bcm5719-llvm-31eeb76f5e3b73f2eb5364ee840789c74723eb1b.zip
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 llvm-svn: 259251
Diffstat (limited to 'llvm/lib/IR')
-rw-r--r--llvm/lib/IR/AttributeImpl.h17
-rw-r--r--llvm/lib/IR/Attributes.cpp15
2 files changed, 20 insertions, 12 deletions
diff --git a/llvm/lib/IR/AttributeImpl.h b/llvm/lib/IR/AttributeImpl.h
index 659f9568b7c..59d09c3d406 100644
--- a/llvm/lib/IR/AttributeImpl.h
+++ b/llvm/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; }
diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp
index ee5a2346970..af5fe85c5c5 100644
--- a/llvm/lib/IR/Attributes.cpp
+++ b/llvm/lib/IR/Attributes.cpp
@@ -498,13 +498,6 @@ AttributeSetNode *AttributeSetNode::get(LLVMContext &C,
return PA;
}
-bool AttributeSetNode::hasAttribute(Attribute::AttrKind Kind) const {
- for (iterator I = begin(), E = end(); I != E; ++I)
- if (I->hasAttribute(Kind))
- return true;
- return false;
-}
-
bool AttributeSetNode::hasAttribute(StringRef Kind) const {
for (iterator I = begin(), E = end(); I != E; ++I)
if (I->hasAttribute(Kind))
@@ -513,9 +506,11 @@ bool AttributeSetNode::hasAttribute(StringRef Kind) const {
}
Attribute AttributeSetNode::getAttribute(Attribute::AttrKind Kind) const {
- for (iterator I = begin(), E = end(); I != E; ++I)
- if (I->hasAttribute(Kind))
- return *I;
+ if (hasAttribute(Kind)) {
+ for (iterator I = begin(), E = end(); I != E; ++I)
+ if (I->hasAttribute(Kind))
+ return *I;
+ }
return Attribute();
}
OpenPOWER on IntegriCloud