aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBill Wendling <isanbard@gmail.com>2013-01-28 21:55:20 +0000
committerBill Wendling <isanbard@gmail.com>2013-01-28 21:55:20 +0000
commit87e10dfefa94f77937c37b0eb51095540d675cbc (patch)
treefb23af640a619069bb117ebf009c1803bb97289d
parentc4e441804ebe5a2d0eadbd9b0840d4f1b12d5a6f (diff)
downloadexternal_llvm-87e10dfefa94f77937c37b0eb51095540d675cbc.zip
external_llvm-87e10dfefa94f77937c37b0eb51095540d675cbc.tar.gz
external_llvm-87e10dfefa94f77937c37b0eb51095540d675cbc.tar.bz2
Remove the AttributeWithIndex class.
The AttributeWithIndex class exposed the interior structure of the AttributeSet class. That was gross. Remove it and all of the code that relied upon it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@173722 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/IR/Attributes.h31
-rw-r--r--lib/IR/AttributeImpl.h19
-rw-r--r--lib/IR/Attributes.cpp146
3 files changed, 85 insertions, 111 deletions
diff --git a/include/llvm/IR/Attributes.h b/include/llvm/IR/Attributes.h
index e6de2bf..46a4444 100644
--- a/include/llvm/IR/Attributes.h
+++ b/include/llvm/IR/Attributes.h
@@ -177,22 +177,7 @@ template<> struct DenseMapInfo<Attribute::AttrKind> {
class AttrBuilder;
class AttributeSetImpl;
-
-//===----------------------------------------------------------------------===//
-/// \class
-/// \brief This is just a pair of values to associate a set of attributes with
-/// an index.
-struct AttributeWithIndex {
- Attribute Attrs; ///< The attributes that are set, or'd together.
- unsigned Index; ///< Index of the parameter for which the attributes apply.
-
- static AttributeWithIndex get(unsigned Idx, Attribute Attrs) {
- AttributeWithIndex P;
- P.Index = Idx;
- P.Attrs = Attrs;
- return P;
- }
-};
+class AttributeSetNode;
//===----------------------------------------------------------------------===//
/// \class
@@ -216,9 +201,17 @@ private:
/// for the result are denoted with Idx = 0.
Attribute getAttributes(unsigned Idx) const;
- /// \brief Create an AttributeSet from the AttributeWithIndex structures.
- /// N.B. this is only temporary. It will be disappearing in the future.
- static AttributeSet get(LLVMContext &C, ArrayRef<AttributeWithIndex> Attrs);
+ /// \brief Create an AttributeSet with the specified parameters in it.
+ static AttributeSet get(LLVMContext &C,
+ ArrayRef<std::pair<uint64_t, Attribute> > Attrs);
+ static AttributeSet get(LLVMContext &C,
+ ArrayRef<std::pair<uint64_t,
+ AttributeSetNode*> > Attrs);
+
+ static AttributeSet getImpl(LLVMContext &C,
+ ArrayRef<std::pair<uint64_t,
+ AttributeSetNode*> > Attrs);
+
explicit AttributeSet(AttributeSetImpl *LI) : pImpl(LI) {}
public:
diff --git a/lib/IR/AttributeImpl.h b/lib/IR/AttributeImpl.h
index 8d5de77..457b6ab 100644
--- a/lib/IR/AttributeImpl.h
+++ b/lib/IR/AttributeImpl.h
@@ -115,7 +115,6 @@ class AttributeSetImpl : public FoldingSetNode {
friend class AttributeSet;
LLVMContext &Context;
- SmallVector<AttributeWithIndex, 4> AttrList;
typedef std::pair<uint64_t, AttributeSetNode*> IndexAttrPair;
SmallVector<IndexAttrPair, 4> AttrNodes;
@@ -124,13 +123,13 @@ class AttributeSetImpl : public FoldingSetNode {
void operator=(const AttributeSetImpl &) LLVM_DELETED_FUNCTION;
AttributeSetImpl(const AttributeSetImpl &) LLVM_DELETED_FUNCTION;
public:
- AttributeSetImpl(LLVMContext &C, ArrayRef<AttributeWithIndex> attrs);
+ AttributeSetImpl(LLVMContext &C,
+ ArrayRef<std::pair<uint64_t, AttributeSetNode*> > attrs)
+ : Context(C), AttrNodes(attrs.begin(), attrs.end()) {}
/// \brief Get the context that created this AttributeSetImpl.
LLVMContext &getContext() { return Context; }
- ArrayRef<AttributeWithIndex> getAttributes() const { return AttrList; }
-
/// \brief Return the number of attributes this AttributeSet contains.
unsigned getNumAttributes() const { return AttrNodes.size(); }
@@ -147,7 +146,7 @@ public:
/// parameter/ function which the attributes apply to.
AttributeSet getSlotAttributes(unsigned Slot) const {
// FIXME: This needs to use AttrNodes instead.
- return AttributeSet::get(Context, AttrList[Slot]);
+ return AttributeSet::get(Context, AttrNodes[Slot]);
}
typedef AttributeSetNode::iterator iterator;
@@ -164,16 +163,8 @@ public:
{ return AttrNodes[Idx].second->end(); }
void Profile(FoldingSetNodeID &ID) const {
- Profile(ID, AttrList);
- }
- static void Profile(FoldingSetNodeID &ID,
- ArrayRef<AttributeWithIndex> AttrList) {
- for (unsigned i = 0, e = AttrList.size(); i != e; ++i) {
- ID.AddInteger(AttrList[i].Index);
- ID.AddInteger(AttrList[i].Attrs.Raw());
- }
+ Profile(ID, AttrNodes);
}
-
static void Profile(FoldingSetNodeID &ID,
ArrayRef<std::pair<uint64_t, AttributeSetNode*> > Nodes) {
for (unsigned i = 0, e = Nodes.size(); i != e; ++i) {
diff --git a/lib/IR/Attributes.cpp b/lib/IR/Attributes.cpp
index 3f0038b..1ac66d5 100644
--- a/lib/IR/Attributes.cpp
+++ b/lib/IR/Attributes.cpp
@@ -1,4 +1,4 @@
-//===-- Attribute.cpp - Implement AttributesList -------------------------===//
+//===-- Attributes.cpp - Implement AttributesList -------------------------===//
//
// The LLVM Compiler Infrastructure
//
@@ -7,7 +7,8 @@
//
//===----------------------------------------------------------------------===//
//
-// This file implements the Attribute, AttributeImpl, AttrBuilder,
+// \file
+// \brief This file implements the Attribute, AttributeImpl, AttrBuilder,
// AttributeSetImpl, and AttributeSet classes.
//
//===----------------------------------------------------------------------===//
@@ -540,44 +541,6 @@ AttributeSetNode *AttributeSetNode::get(LLVMContext &C,
// AttributeSetImpl Definition
//===----------------------------------------------------------------------===//
-AttributeSetImpl::
-AttributeSetImpl(LLVMContext &C,
- ArrayRef<AttributeWithIndex> attrs)
- : Context(C), AttrList(attrs.begin(), attrs.end()) {
- for (unsigned I = 0, E = attrs.size(); I != E; ++I) {
- const AttributeWithIndex &AWI = attrs[I];
- uint64_t Mask = AWI.Attrs.Raw();
- SmallVector<Attribute, 8> Attrs;
-
- for (Attribute::AttrKind II = Attribute::None;
- II != Attribute::EndAttrKinds; II = Attribute::AttrKind(II + 1)) {
- if (uint64_t A = (Mask & AttributeImpl::getAttrMask(II))) {
- AttrBuilder B;
-
- if (II == Attribute::Alignment)
- B.addAlignmentAttr(1ULL << ((A >> 16) - 1));
- else if (II == Attribute::StackAlignment)
- B.addStackAlignmentAttr(1ULL << ((A >> 26) - 1));
- else
- B.addAttribute(II);
-
- Attrs.push_back(Attribute::get(C, B));
- }
- }
-
- AttrNodes.push_back(std::make_pair(AWI.Index,
- AttributeSetNode::get(C, Attrs)));
- }
-
- assert(AttrNodes.size() == AttrList.size() &&
- "Number of attributes is different between lists!");
-#ifndef NDEBUG
- for (unsigned I = 0, E = AttrNodes.size(); I != E; ++I)
- assert((I == 0 || AttrNodes[I - 1].first < AttrNodes[I].first) &&
- "Attributes not in ascending order!");
-#endif
-}
-
uint64_t AttributeSetImpl::Raw(uint64_t Index) const {
for (unsigned I = 0, E = getNumAttributes(); I != E; ++I) {
if (getSlotIndex(I) != Index) continue;
@@ -587,9 +550,6 @@ uint64_t AttributeSetImpl::Raw(uint64_t Index) const {
for (AttributeSetNode::const_iterator II = ASN->begin(),
IE = ASN->end(); II != IE; ++II)
B.addAttributes(*II);
-
- assert(B.Raw() == AttrList[I].Attrs.Raw() &&
- "Attributes aren't the same!");
return B.Raw();
}
@@ -604,7 +564,8 @@ AttributeSet AttributeSet::getParamAttributes(unsigned Idx) const {
// FIXME: Remove.
return pImpl && hasAttributes(Idx) ?
AttributeSet::get(pImpl->getContext(),
- AttributeWithIndex::get(Idx, getAttributes(Idx))) :
+ ArrayRef<std::pair<uint64_t, Attribute> >(
+ std::make_pair(Idx, getAttributes(Idx)))) :
AttributeSet();
}
@@ -612,8 +573,9 @@ AttributeSet AttributeSet::getRetAttributes() const {
// FIXME: Remove.
return pImpl && hasAttributes(ReturnIndex) ?
AttributeSet::get(pImpl->getContext(),
- AttributeWithIndex::get(ReturnIndex,
- getAttributes(ReturnIndex))) :
+ ArrayRef<std::pair<uint64_t, Attribute> >(
+ std::make_pair(ReturnIndex,
+ getAttributes(ReturnIndex)))) :
AttributeSet();
}
@@ -621,27 +583,15 @@ AttributeSet AttributeSet::getFnAttributes() const {
// FIXME: Remove.
return pImpl && hasAttributes(FunctionIndex) ?
AttributeSet::get(pImpl->getContext(),
- AttributeWithIndex::get(FunctionIndex,
- getAttributes(FunctionIndex))) :
+ ArrayRef<std::pair<uint64_t, Attribute> >(
+ std::make_pair(FunctionIndex,
+ getAttributes(FunctionIndex)))) :
AttributeSet();
}
-AttributeSet AttributeSet::get(LLVMContext &C,
- ArrayRef<AttributeWithIndex> Attrs) {
- // If there are no attributes then return a null AttributesList pointer.
- if (Attrs.empty())
- return AttributeSet();
-
-#ifndef NDEBUG
- for (unsigned i = 0, e = Attrs.size(); i != e; ++i) {
- assert(Attrs[i].Attrs.hasAttributes() &&
- "Pointless attribute!");
- assert((!i || Attrs[i-1].Index < Attrs[i].Index) &&
- "Misordered AttributesList!");
- }
-#endif
-
- // Otherwise, build a key to look up the existing attributes.
+AttributeSet AttributeSet::getImpl(LLVMContext &C,
+ ArrayRef<std::pair<uint64_t,
+ AttributeSetNode*> > Attrs) {
LLVMContextImpl *pImpl = C.pImpl;
FoldingSetNodeID ID;
AttributeSetImpl::Profile(ID, Attrs);
@@ -660,35 +610,75 @@ AttributeSet AttributeSet::get(LLVMContext &C,
return AttributeSet(PA);
}
+AttributeSet AttributeSet::get(LLVMContext &C,
+ ArrayRef<std::pair<uint64_t, Attribute> > Attrs){
+ // If there are no attributes then return a null AttributesList pointer.
+ if (Attrs.empty())
+ return AttributeSet();
+
+#ifndef NDEBUG
+ for (unsigned i = 0, e = Attrs.size(); i != e; ++i) {
+ assert((!i || Attrs[i-1].first <= Attrs[i].first) &&
+ "Misordered Attributes list!");
+ assert(Attrs[i].second.hasAttributes() &&
+ "Pointless attribute!");
+ }
+#endif
+
+ // Create a vector if (uint64_t, AttributeSetNode*) pairs from the attributes
+ // list.
+ SmallVector<std::pair<uint64_t, AttributeSetNode*>, 8> AttrPairVec;
+ for (ArrayRef<std::pair<uint64_t, Attribute> >::iterator I = Attrs.begin(),
+ E = Attrs.end(); I != E; ) {
+ uint64_t Index = I->first;
+ SmallVector<Attribute, 4> AttrVec;
+ while (I->first == Index && I != E) {
+ AttrVec.push_back(I->second);
+ ++I;
+ }
+
+ AttrPairVec.push_back(std::make_pair(Index,
+ AttributeSetNode::get(C, AttrVec)));
+ }
+
+ return getImpl(C, AttrPairVec);
+}
+
+AttributeSet AttributeSet::get(LLVMContext &C,
+ ArrayRef<std::pair<uint64_t,
+ AttributeSetNode*> > Attrs) {
+ // If there are no attributes then return a null AttributesList pointer.
+ if (Attrs.empty())
+ return AttributeSet();
+
+ return getImpl(C, Attrs);
+}
+
AttributeSet AttributeSet::get(LLVMContext &C, unsigned Idx, AttrBuilder &B) {
- // FIXME: This should be implemented as a loop that creates the
- // AttributeWithIndexes that then are used to create the AttributeSet.
if (!B.hasAttributes())
return AttributeSet();
- return get(C, AttributeWithIndex::get(Idx, Attribute::get(C, B)));
+ return get(C, ArrayRef<std::pair<uint64_t, Attribute> >(
+ std::make_pair(Idx, Attribute::get(C, B))));
}
AttributeSet AttributeSet::get(LLVMContext &C, unsigned Idx,
ArrayRef<Attribute::AttrKind> Kind) {
- // FIXME: This is temporary. Ultimately, the AttributeWithIndex will be
- // replaced by an object that holds multiple Attribute::AttrKinds.
- AttrBuilder B;
+ SmallVector<std::pair<uint64_t, Attribute>, 8> Attrs;
for (ArrayRef<Attribute::AttrKind>::iterator I = Kind.begin(),
E = Kind.end(); I != E; ++I)
- B.addAttribute(*I);
- return get(C, Idx, B);
+ Attrs.push_back(std::make_pair(Idx, Attribute::get(C, *I)));
+ return get(C, Attrs);
}
AttributeSet AttributeSet::get(LLVMContext &C, ArrayRef<AttributeSet> Attrs) {
- SmallVector<AttributeWithIndex, 8> AttrList;
- for (ArrayRef<AttributeSet>::iterator I = Attrs.begin(), E = Attrs.end();
- I != E; ++I) {
- AttributeSet AS = *I;
+ SmallVector<std::pair<uint64_t, AttributeSetNode*>, 8> AttrNodeVec;
+ for (unsigned I = 0, E = Attrs.size(); I != E; ++I) {
+ AttributeSet AS = Attrs[I];
if (!AS.pImpl) continue;
- AttrList.append(AS.pImpl->AttrList.begin(), AS.pImpl->AttrList.end());
+ AttrNodeVec.append(AS.pImpl->AttrNodes.begin(), AS.pImpl->AttrNodes.end());
}
- return get(C, AttrList);
+ return get(C, AttrNodeVec);
}
/// \brief Return the number of slots used in this attribute list. This is the