Skip to content

Commit

Permalink
[IR] Sink some AttributeListImpl methods out of headers NFC
Browse files Browse the repository at this point in the history
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@299906 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
rnk committed Apr 11, 2017
1 parent f47b8f1 commit a8ca301
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 41 deletions.
44 changes: 3 additions & 41 deletions lib/IR/AttributeImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,38 +172,7 @@ class AttributeListImpl final

public:
AttributeListImpl(LLVMContext &C,
ArrayRef<std::pair<unsigned, AttributeSetNode *>> Slots)
: Context(C), NumSlots(Slots.size()), AvailableFunctionAttrs(0) {
static_assert(Attribute::EndAttrKinds <=
sizeof(AvailableFunctionAttrs) * CHAR_BIT,
"Too many attributes");

#ifndef NDEBUG
if (Slots.size() >= 2) {
for (const std::pair<unsigned, AttributeSetNode *> *i = Slots.begin() + 1,
*e = Slots.end();
i != e; ++i) {
assert((i-1)->first <= i->first && "Attribute set not ordered!");
}
}
#endif
// There's memory after the node where we can store the entries in.
std::copy(Slots.begin(), Slots.end(), getTrailingObjects<IndexAttrPair>());

// Initialize AvailableFunctionAttrs summary bitset.
if (NumSlots > 0) {
static_assert(AttributeList::FunctionIndex == ~0u,
"FunctionIndex should be biggest possible index");
const std::pair<unsigned, AttributeSetNode *> &Last = Slots.back();
if (Last.first == AttributeList::FunctionIndex) {
const AttributeSetNode *Node = Last.second;
for (Attribute I : *Node) {
if (!I.isStringAttribute())
AvailableFunctionAttrs |= ((uint64_t)1) << I.getKindAsEnum();
}
}
}
}
ArrayRef<std::pair<unsigned, AttributeSetNode *>> Slots);

// AttributesSetImpt is uniqued, these should not be available.
AttributeListImpl(const AttributeListImpl &) = delete;
Expand Down Expand Up @@ -250,16 +219,9 @@ class AttributeListImpl final
iterator begin(unsigned Slot) const { return getSlotNode(Slot)->begin(); }
iterator end(unsigned Slot) const { return getSlotNode(Slot)->end(); }

void Profile(FoldingSetNodeID &ID) const {
Profile(ID, makeArrayRef(getNode(0), getNumSlots()));
}
void Profile(FoldingSetNodeID &ID) const;
static void Profile(FoldingSetNodeID &ID,
ArrayRef<std::pair<unsigned, AttributeSetNode*>> Nodes) {
for (const auto &Node : Nodes) {
ID.AddInteger(Node.first);
ID.AddPointer(Node.second);
}
}
ArrayRef<std::pair<unsigned, AttributeSetNode*>> Nodes);

void dump() const;
};
Expand Down
46 changes: 46 additions & 0 deletions lib/IR/Attributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,52 @@ std::string AttributeSetNode::getAsString(bool InAttrGrp) const {
// AttributeListImpl Definition
//===----------------------------------------------------------------------===//

AttributeListImpl::AttributeListImpl(
LLVMContext &C, ArrayRef<std::pair<unsigned, AttributeSetNode *>> Slots)
: Context(C), NumSlots(Slots.size()), AvailableFunctionAttrs(0) {
#ifndef NDEBUG
if (Slots.size() >= 2) {
auto &PrevPair = Slots.front();
for (auto &CurPair : Slots.drop_front()) {
assert(PrevPair.first <= CurPair.first && "Attribute set not ordered!");
}
}
#endif

// There's memory after the node where we can store the entries in.
std::copy(Slots.begin(), Slots.end(), getTrailingObjects<IndexAttrPair>());

// Initialize AvailableFunctionAttrs summary bitset.
if (NumSlots > 0) {
static_assert(Attribute::EndAttrKinds <=
sizeof(AvailableFunctionAttrs) * CHAR_BIT,
"Too many attributes");
static_assert(AttributeList::FunctionIndex == ~0u,
"FunctionIndex should be biggest possible index");
const std::pair<unsigned, AttributeSetNode *> &Last = Slots.back();
if (Last.first == AttributeList::FunctionIndex) {
const AttributeSetNode *Node = Last.second;
for (Attribute I : *Node) {
if (!I.isStringAttribute())
AvailableFunctionAttrs |= ((uint64_t)1) << I.getKindAsEnum();
}
}
}
}

void AttributeListImpl::Profile(FoldingSetNodeID &ID) const {
Profile(ID, makeArrayRef(getNode(0), getNumSlots()));
}

void AttributeListImpl::Profile(
FoldingSetNodeID &ID,
ArrayRef<std::pair<unsigned, AttributeSetNode *>> Nodes) {
for (const auto &Node : Nodes) {
ID.AddInteger(Node.first);
ID.AddPointer(Node.second);
}
}

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD void AttributeListImpl::dump() const {
AttributeList(const_cast<AttributeListImpl *>(this)).dump();
Expand Down

0 comments on commit a8ca301

Please sign in to comment.