[llvm] r174228 - Change the AttributeImpl to hold a single Constant* for the values.
Bill Wendling
isanbard at gmail.com
Fri Feb 1 14:32:30 PST 2013
Author: void
Date: Fri Feb 1 16:32:30 2013
New Revision: 174228
URL: http://llvm.org/viewvc/llvm-project?rev=174228&view=rev
Log:
Change the AttributeImpl to hold a single Constant* for the values.
This Constant could be an aggregate to represent multiple values.
Modified:
llvm/trunk/include/llvm/IR/Attributes.h
llvm/trunk/lib/IR/AttributeImpl.h
llvm/trunk/lib/IR/Attributes.cpp
Modified: llvm/trunk/include/llvm/IR/Attributes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Attributes.h?rev=174228&r1=174227&r2=174228&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/Attributes.h (original)
+++ llvm/trunk/include/llvm/IR/Attributes.h Fri Feb 1 16:32:30 2013
@@ -128,11 +128,13 @@ public:
/// \brief Return true if the attribute is present.
bool hasAttribute(AttrKind Val) const;
- /// \brief Return the kind of this attribute.
+ /// \brief Return the kind of this attribute: enum or string.
Constant *getAttributeKind() const;
- /// \brief Return the value (if present) of the non-target-specific attribute.
- ArrayRef<Constant*> getAttributeValues() const;
+ /// \brief Return the values (if present) of the attribute. This may be a
+ /// ConstantVector to represent a list of values associated with the
+ /// attribute.
+ Constant *getAttributeValues() const;
/// \brief Returns the alignment field of an attribute as a byte alignment
/// value.
Modified: llvm/trunk/lib/IR/AttributeImpl.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/AttributeImpl.h?rev=174228&r1=174227&r2=174228&view=diff
==============================================================================
--- llvm/trunk/lib/IR/AttributeImpl.h (original)
+++ llvm/trunk/lib/IR/AttributeImpl.h Fri Feb 1 16:32:30 2013
@@ -30,24 +30,23 @@ class LLVMContext;
/// \brief This class represents a single, uniqued attribute. That attribute
/// could be a single enum, a tuple, or a string.
class AttributeImpl : public FoldingSetNode {
- LLVMContext &Context;
- Constant *Kind;
- SmallVector<Constant*, 0> Vals;
+ LLVMContext &Context; ///< Global context for uniquing objects
+ Constant *Kind; ///< Kind of attribute: enum or string
+ Constant *Values; ///< Values associated with the attribute
// AttributesImpl is uniqued, these should not be publicly available.
void operator=(const AttributeImpl &) LLVM_DELETED_FUNCTION;
AttributeImpl(const AttributeImpl &) LLVM_DELETED_FUNCTION;
public:
- AttributeImpl(LLVMContext &C, Constant *Kind,
- ArrayRef<Constant*> Vals = ArrayRef<Constant*>())
- : Context(C), Kind(Kind), Vals(Vals.begin(), Vals.end()) {}
+ AttributeImpl(LLVMContext &C, Constant *Kind, Constant *Values = 0)
+ : Context(C), Kind(Kind), Values(Values) {}
LLVMContext &getContext() { return Context; }
bool hasAttribute(Attribute::AttrKind A) const;
Constant *getAttributeKind() const { return Kind; }
- ArrayRef<Constant*> getAttributeValues() const { return Vals; }
+ Constant *getAttributeValues() const { return Values; }
uint64_t getAlignment() const;
uint64_t getStackAlignment() const;
@@ -63,13 +62,12 @@ public:
bool operator<(const AttributeImpl &AI) const;
void Profile(FoldingSetNodeID &ID) const {
- Profile(ID, Kind, Vals);
+ Profile(ID, Kind, Values);
}
- static void Profile(FoldingSetNodeID &ID, Constant *Kind,
- ArrayRef<Constant*> Vals) {
+ static void Profile(FoldingSetNodeID &ID, Constant *Kind, Constant *Values) {
ID.AddPointer(Kind);
- for (unsigned I = 0, E = Vals.size(); I != E; ++I)
- ID.AddPointer(Vals[I]);
+ if (Values)
+ ID.AddPointer(Values);
}
// FIXME: Remove this!
Modified: llvm/trunk/lib/IR/Attributes.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Attributes.cpp?rev=174228&r1=174227&r2=174228&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Attributes.cpp (original)
+++ llvm/trunk/lib/IR/Attributes.cpp Fri Feb 1 16:32:30 2013
@@ -84,8 +84,8 @@ Constant *Attribute::getAttributeKind()
return pImpl ? pImpl->getAttributeKind() : 0;
}
-ArrayRef<Constant*> Attribute::getAttributeValues() const {
- return pImpl ? pImpl->getAttributeValues() : ArrayRef<Constant*>();
+Constant *Attribute::getAttributeValues() const {
+ return pImpl ? pImpl->getAttributeValues() : 0;
}
/// This returns the alignment field of an attribute as a byte alignment value.
@@ -186,24 +186,22 @@ std::string Attribute::getAsString() con
//
// "kind"
// "kind" = "value"
- // "kind" = ("value1" "value2" "value3" )
+ // "kind" = ( "value1" "value2" "value3" )
//
if (ConstantDataArray *CDA =
dyn_cast<ConstantDataArray>(pImpl->getAttributeKind())) {
std::string Result;
Result += '\"' + CDA->getAsString().str() + '"';
- ArrayRef<Constant*> Vals = pImpl->getAttributeValues();
- if (Vals.empty()) return Result;
+ Constant *Vals = pImpl->getAttributeValues();
+ if (!Vals) return Result;
+
+ // FIXME: This should support more than just ConstantDataArrays. Also,
+ // support a vector of attribute values.
+
Result += " = ";
- if (Vals.size() > 1) Result += '(';
- for (ArrayRef<Constant*>::iterator I = Vals.begin(), E = Vals.end();
- I != E; ) {
- ConstantDataArray *CDA = cast<ConstantDataArray>(*I++);
- Result += '\"' + CDA->getAsString().str() + '"';
- if (I != E) Result += ' ';
- }
- if (Vals.size() > 1) Result += ')';
+ Result += '\"' + cast<ConstantDataArray>(Vals)->getAsString().str() + '"';
+
return Result;
}
@@ -237,13 +235,13 @@ bool AttributeImpl::hasAttribute(Attribu
uint64_t AttributeImpl::getAlignment() const {
assert(hasAttribute(Attribute::Alignment) &&
"Trying to retrieve the alignment from a non-alignment attr!");
- return cast<ConstantInt>(Vals[0])->getZExtValue();
+ return cast<ConstantInt>(Values)->getZExtValue();
}
uint64_t AttributeImpl::getStackAlignment() const {
assert(hasAttribute(Attribute::StackAlignment) &&
"Trying to retrieve the stack alignment from a non-alignment attr!");
- return cast<ConstantInt>(Vals[0])->getZExtValue();
+ return cast<ConstantInt>(Values)->getZExtValue();
}
bool AttributeImpl::operator==(Attribute::AttrKind kind) const {
More information about the llvm-commits
mailing list