aboutsummaryrefslogtreecommitdiffstats
path: root/lib/IR
diff options
context:
space:
mode:
authorBill Wendling <isanbard@gmail.com>2013-01-25 23:09:36 +0000
committerBill Wendling <isanbard@gmail.com>2013-01-25 23:09:36 +0000
commit8e47daf2858e980210f3e1f007036b24da342c29 (patch)
treec29ac046d2219e5f62bd06e74078de858fcb40a5 /lib/IR
parenta8b289b70d5ef416608bb71a874b8b4fe80158e1 (diff)
downloadexternal_llvm-8e47daf2858e980210f3e1f007036b24da342c29.zip
external_llvm-8e47daf2858e980210f3e1f007036b24da342c29.tar.gz
external_llvm-8e47daf2858e980210f3e1f007036b24da342c29.tar.bz2
Remove some introspection functions.
The 'getSlot' function and its ilk allow introspection into the AttributeSet class. However, that class should be opaque. Allow access through accessor methods instead. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@173522 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/IR')
-rw-r--r--lib/IR/AttributeImpl.h6
-rw-r--r--lib/IR/Attributes.cpp138
-rw-r--r--lib/IR/Verifier.cpp4
3 files changed, 89 insertions, 59 deletions
diff --git a/lib/IR/AttributeImpl.h b/lib/IR/AttributeImpl.h
index ebd90e2..d7ebec5 100644
--- a/lib/IR/AttributeImpl.h
+++ b/lib/IR/AttributeImpl.h
@@ -104,6 +104,8 @@ public:
/// \brief This class represents a set of attributes that apply to the function,
/// return type, and parameters.
class AttributeSetImpl : public FoldingSetNode {
+ friend class AttributeSet;
+
LLVMContext &Context;
SmallVector<AttributeWithIndex, 4> AttrList;
@@ -126,6 +128,10 @@ public:
// FIXME: This needs to use AttrNodes instead.
return AttrList[Slot].Index;
}
+ AttributeSet getSlotAttributes(unsigned Slot) const {
+ // FIXME: This needs to use AttrNodes instead.
+ return AttributeSet::get(Context, AttrList[Slot]);
+ }
void Profile(FoldingSetNodeID &ID) const {
Profile(ID, AttrList);
diff --git a/lib/IR/Attributes.cpp b/lib/IR/Attributes.cpp
index 538d9fe..f44a0fc 100644
--- a/lib/IR/Attributes.cpp
+++ b/lib/IR/Attributes.cpp
@@ -103,63 +103,6 @@ uint64_t Attribute::Raw() const {
return pImpl ? pImpl->Raw() : 0;
}
-Attribute Attribute::typeIncompatible(Type *Ty) {
- AttrBuilder Incompatible;
-
- if (!Ty->isIntegerTy())
- // Attribute that only apply to integers.
- Incompatible.addAttribute(Attribute::SExt)
- .addAttribute(Attribute::ZExt);
-
- if (!Ty->isPointerTy())
- // Attribute that only apply to pointers.
- Incompatible.addAttribute(Attribute::ByVal)
- .addAttribute(Attribute::Nest)
- .addAttribute(Attribute::NoAlias)
- .addAttribute(Attribute::NoCapture)
- .addAttribute(Attribute::StructRet);
-
- return Attribute::get(Ty->getContext(), Incompatible);
-}
-
-/// encodeLLVMAttributesForBitcode - This returns an integer containing an
-/// encoding of all the LLVM attributes found in the given attribute bitset.
-/// Any change to this encoding is a breaking change to bitcode compatibility.
-uint64_t Attribute::encodeLLVMAttributesForBitcode(Attribute Attrs) {
- // FIXME: It doesn't make sense to store the alignment information as an
- // expanded out value, we should store it as a log2 value. However, we can't
- // just change that here without breaking bitcode compatibility. If this ever
- // becomes a problem in practice, we should introduce new tag numbers in the
- // bitcode file and have those tags use a more efficiently encoded alignment
- // field.
-
- // Store the alignment in the bitcode as a 16-bit raw value instead of a 5-bit
- // log2 encoded value. Shift the bits above the alignment up by 11 bits.
- uint64_t EncodedAttrs = Attrs.Raw() & 0xffff;
- if (Attrs.hasAttribute(Attribute::Alignment))
- EncodedAttrs |= Attrs.getAlignment() << 16;
- EncodedAttrs |= (Attrs.Raw() & (0xffffULL << 21)) << 11;
- return EncodedAttrs;
-}
-
-/// decodeLLVMAttributesForBitcode - This returns an attribute bitset containing
-/// the LLVM attributes that have been decoded from the given integer. This
-/// function must stay in sync with 'encodeLLVMAttributesForBitcode'.
-Attribute Attribute::decodeLLVMAttributesForBitcode(LLVMContext &C,
- uint64_t EncodedAttrs) {
- // The alignment is stored as a 16-bit raw value from bits 31--16. We shift
- // the bits above 31 down by 11 bits.
- unsigned Alignment = (EncodedAttrs & (0xffffULL << 16)) >> 16;
- assert((!Alignment || isPowerOf2_32(Alignment)) &&
- "Alignment must be a power of two.");
-
- AttrBuilder B(EncodedAttrs & 0xffff);
- if (Alignment)
- B.addAlignmentAttr(Alignment);
- B.addRawValue((EncodedAttrs & (0xffffULL << 32)) >> 11);
- return Attribute::get(C, B);
-}
-
std::string Attribute::getAsString() const {
std::string Result;
if (hasAttribute(Attribute::ZExt))
@@ -666,6 +609,18 @@ AttributeSet AttributeSet::get(LLVMContext &C, unsigned Idx,
return get(C, AttributeWithIndex::get(Idx, Attribute::get(C, Kind)));
}
+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;
+ if (!AS.AttrList) continue;
+ AttrList.append(AS.AttrList->AttrList.begin(), AS.AttrList->AttrList.end());
+ }
+
+ return get(C, AttrList);
+}
+
//===----------------------------------------------------------------------===//
// AttributeSet Method Implementations
//===----------------------------------------------------------------------===//
@@ -688,6 +643,12 @@ unsigned AttributeSet::getSlotIndex(unsigned Slot) const {
return AttrList->getSlotIndex(Slot);
}
+AttributeSet AttributeSet::getSlotAttributes(unsigned Slot) const {
+ assert(AttrList && Slot < AttrList->getNumAttributes() &&
+ "Slot # out of range!");
+ return AttrList->getSlotAttributes(Slot);
+}
+
/// getSlot - Return the AttributeWithIndex at the specified slot. This
/// holds a number plus a set of attributes.
const AttributeWithIndex &AttributeSet::getSlot(unsigned Slot) const {
@@ -859,3 +820,66 @@ void AttributeSet::dump() const {
dbgs() << "]\n";
}
+
+//===----------------------------------------------------------------------===//
+// AttributeFuncs Function Defintions
+//===----------------------------------------------------------------------===//
+
+Attribute AttributeFuncs::typeIncompatible(Type *Ty) {
+ AttrBuilder Incompatible;
+
+ if (!Ty->isIntegerTy())
+ // Attribute that only apply to integers.
+ Incompatible.addAttribute(Attribute::SExt)
+ .addAttribute(Attribute::ZExt);
+
+ if (!Ty->isPointerTy())
+ // Attribute that only apply to pointers.
+ Incompatible.addAttribute(Attribute::ByVal)
+ .addAttribute(Attribute::Nest)
+ .addAttribute(Attribute::NoAlias)
+ .addAttribute(Attribute::NoCapture)
+ .addAttribute(Attribute::StructRet);
+
+ return Attribute::get(Ty->getContext(), Incompatible);
+}
+
+/// encodeLLVMAttributesForBitcode - This returns an integer containing an
+/// encoding of all the LLVM attributes found in the given attribute bitset.
+/// Any change to this encoding is a breaking change to bitcode compatibility.
+uint64_t AttributeFuncs::encodeLLVMAttributesForBitcode(AttributeSet Attrs,
+ unsigned Index) {
+ // FIXME: It doesn't make sense to store the alignment information as an
+ // expanded out value, we should store it as a log2 value. However, we can't
+ // just change that here without breaking bitcode compatibility. If this ever
+ // becomes a problem in practice, we should introduce new tag numbers in the
+ // bitcode file and have those tags use a more efficiently encoded alignment
+ // field.
+
+ // Store the alignment in the bitcode as a 16-bit raw value instead of a 5-bit
+ // log2 encoded value. Shift the bits above the alignment up by 11 bits.
+ uint64_t EncodedAttrs = Attrs.Raw(Index) & 0xffff;
+ if (Attrs.hasAttribute(Index, Attribute::Alignment))
+ EncodedAttrs |= Attrs.getParamAlignment(Index) << 16;
+ EncodedAttrs |= (Attrs.Raw(Index) & (0xffffULL << 21)) << 11;
+ return EncodedAttrs;
+}
+
+/// decodeLLVMAttributesForBitcode - This returns an attribute bitset containing
+/// the LLVM attributes that have been decoded from the given integer. This
+/// function must stay in sync with 'encodeLLVMAttributesForBitcode'.
+Attribute AttributeFuncs::decodeLLVMAttributesForBitcode(LLVMContext &C,
+ uint64_t EncodedAttrs){
+ // The alignment is stored as a 16-bit raw value from bits 31--16. We shift
+ // the bits above 31 down by 11 bits.
+ unsigned Alignment = (EncodedAttrs & (0xffffULL << 16)) >> 16;
+ assert((!Alignment || isPowerOf2_32(Alignment)) &&
+ "Alignment must be a power of two.");
+
+ AttrBuilder B(EncodedAttrs & 0xffff);
+ if (Alignment)
+ B.addAlignmentAttr(Alignment);
+ B.addRawValue((EncodedAttrs & (0xffffULL << 32)) >> 11);
+ return Attribute::get(C, B);
+}
+
diff --git a/lib/IR/Verifier.cpp b/lib/IR/Verifier.cpp
index 9a482f1..39f95fa 100644
--- a/lib/IR/Verifier.cpp
+++ b/lib/IR/Verifier.cpp
@@ -693,9 +693,9 @@ void Verifier::VerifyParameterAttrs(AttributeSet Attrs, uint64_t Idx, Type *Ty,
"'noinline and alwaysinline' are incompatible!", V);
Assert1(!AttrBuilder(Attrs, Idx).
- hasAttributes(Attribute::typeIncompatible(Ty)),
+ hasAttributes(AttributeFuncs::typeIncompatible(Ty)),
"Wrong types for attribute: " +
- Attribute::typeIncompatible(Ty).getAsString(), V);
+ AttributeFuncs::typeIncompatible(Ty).getAsString(), V);
if (PointerType *PTy = dyn_cast<PointerType>(Ty))
Assert1(!Attrs.hasAttribute(Idx, Attribute::ByVal) ||