llvm.org GIT mirror llvm / 8e47daf
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 Bill Wendling 7 years ago
10 changed file(s) with 143 addition(s) and 94 deletion(s). Raw diff Collapse all Expand all
145145
146146 uint64_t Raw() const;
147147
148 /// \brief Which attributes cannot be applied to a type.
149 static Attribute typeIncompatible(Type *Ty);
150
151 /// \brief This returns an integer containing an encoding of all the LLVM
152 /// attributes found in the given attribute bitset. Any change to this
153 /// encoding is a breaking change to bitcode compatibility.
154 static uint64_t encodeLLVMAttributesForBitcode(Attribute Attrs);
155
156 /// \brief This returns an attribute bitset containing the LLVM attributes
157 /// that have been decoded from the given integer. This function must stay in
158 /// sync with 'encodeLLVMAttributesForBitcode'.
159 static Attribute decodeLLVMAttributesForBitcode(LLVMContext &C,
160 uint64_t EncodedAttrs);
161
162148 /// \brief The Attribute is converted to a string of equivalent mnemonic. This
163149 /// is, presumably, for writing out the mnemonics for the assembly writer.
164150 std::string getAsString() const;
235221
236222 /// \brief Return an AttributeSet with the specified parameters in it.
237223 static AttributeSet get(LLVMContext &C, ArrayRef Attrs);
224 static AttributeSet get(LLVMContext &C, ArrayRef Attrs);
238225 static AttributeSet get(LLVMContext &C, unsigned Idx,
239226 Attribute::AttrKind Kind);
240227 static AttributeSet get(LLVMContext &C, unsigned Idx, AttrBuilder &B);
295282 /// \brief Return true if attribute exists at the given index.
296283 bool hasAttributes(unsigned Index) const;
297284
285 /// \brief Returns the alignment field of an attribute as a byte alignment
286 /// value.
287 unsigned getAlignment(unsigned Index) const;
288
298289 /// \brief Get the stack alignment.
299290 unsigned getStackAlignment(unsigned Index) const;
300291
340331
341332 /// \brief Return the index for the given slot.
342333 unsigned getSlotIndex(unsigned Slot) const;
334
335 /// \brief Return the attributes at the given slot.
336 AttributeSet getSlotAttributes(unsigned Slot) const;
343337
344338 /// \brief Return the AttributeWithIndex at the specified slot. This holds a
345339 /// index number plus a set of attributes.
478472 }
479473 };
480474
475 namespace AttributeFuncs {
476
477 /// \brief Which attributes cannot be applied to a type.
478 Attribute typeIncompatible(Type *Ty);
479
480 /// \brief This returns an integer containing an encoding of all the LLVM
481 /// attributes found in the given attribute bitset. Any change to this encoding
482 /// is a breaking change to bitcode compatibility.
483 uint64_t encodeLLVMAttributesForBitcode(AttributeSet Attrs, unsigned Index);
484
485 /// \brief This returns an attribute bitset containing the LLVM attributes that
486 /// have been decoded from the given integer. This function must stay in sync
487 /// with 'encodeLLVMAttributesForBitcode'.
488 Attribute decodeLLVMAttributesForBitcode(LLVMContext &C,
489 uint64_t EncodedAttrs);
490
491 } // end AttributeFuncs namespace
492
481493 } // end llvm namespace
482494
483495 #endif
464464
465465 for (unsigned i = 0, e = Record.size(); i != e; i += 2) {
466466 Attribute ReconstitutedAttr =
467 Attribute::decodeLLVMAttributesForBitcode(Context, Record[i+1]);
467 AttributeFuncs::decodeLLVMAttributesForBitcode(Context, Record[i+1]);
468468 Record[i+1] = ReconstitutedAttr.Raw();
469469 }
470470
172172 for (unsigned i = 0, e = Attrs.size(); i != e; ++i) {
173173 const AttributeSet &A = Attrs[i];
174174 for (unsigned i = 0, e = A.getNumSlots(); i != e; ++i) {
175 const AttributeWithIndex &PAWI = A.getSlot(i);
176 Record.push_back(A.getSlotIndex(i));
177 Record.push_back(Attribute::encodeLLVMAttributesForBitcode(PAWI.Attrs));
175 unsigned Index = A.getSlotIndex(i);
176 Record.push_back(Index);
177 Record.push_back(AttributeFuncs::
178 encodeLLVMAttributesForBitcode(A.getSlotAttributes(i),
179 Index));
178180 }
179181
180182 Stream.EmitRecord(bitc::PARAMATTR_CODE_ENTRY, Record);
103103 /// \brief This class represents a set of attributes that apply to the function,
104104 /// return type, and parameters.
105105 class AttributeSetImpl : public FoldingSetNode {
106 friend class AttributeSet;
107
106108 LLVMContext &Context;
107109 SmallVector AttrList;
108110
124126 unsigned getSlotIndex(unsigned Slot) const {
125127 // FIXME: This needs to use AttrNodes instead.
126128 return AttrList[Slot].Index;
129 }
130 AttributeSet getSlotAttributes(unsigned Slot) const {
131 // FIXME: This needs to use AttrNodes instead.
132 return AttributeSet::get(Context, AttrList[Slot]);
127133 }
128134
129135 void Profile(FoldingSetNodeID &ID) const {
100100
101101 uint64_t Attribute::Raw() const {
102102 return pImpl ? pImpl->Raw() : 0;
103 }
104
105 Attribute Attribute::typeIncompatible(Type *Ty) {
106 AttrBuilder Incompatible;
107
108 if (!Ty->isIntegerTy())
109 // Attribute that only apply to integers.
110 Incompatible.addAttribute(Attribute::SExt)
111 .addAttribute(Attribute::ZExt);
112
113 if (!Ty->isPointerTy())
114 // Attribute that only apply to pointers.
115 Incompatible.addAttribute(Attribute::ByVal)
116 .addAttribute(Attribute::Nest)
117 .addAttribute(Attribute::NoAlias)
118 .addAttribute(Attribute::NoCapture)
119 .addAttribute(Attribute::StructRet);
120
121 return Attribute::get(Ty->getContext(), Incompatible);
122 }
123
124 /// encodeLLVMAttributesForBitcode - This returns an integer containing an
125 /// encoding of all the LLVM attributes found in the given attribute bitset.
126 /// Any change to this encoding is a breaking change to bitcode compatibility.
127 uint64_t Attribute::encodeLLVMAttributesForBitcode(Attribute Attrs) {
128 // FIXME: It doesn't make sense to store the alignment information as an
129 // expanded out value, we should store it as a log2 value. However, we can't
130 // just change that here without breaking bitcode compatibility. If this ever
131 // becomes a problem in practice, we should introduce new tag numbers in the
132 // bitcode file and have those tags use a more efficiently encoded alignment
133 // field.
134
135 // Store the alignment in the bitcode as a 16-bit raw value instead of a 5-bit
136 // log2 encoded value. Shift the bits above the alignment up by 11 bits.
137 uint64_t EncodedAttrs = Attrs.Raw() & 0xffff;
138 if (Attrs.hasAttribute(Attribute::Alignment))
139 EncodedAttrs |= Attrs.getAlignment() << 16;
140 EncodedAttrs |= (Attrs.Raw() & (0xffffULL << 21)) << 11;
141 return EncodedAttrs;
142 }
143
144 /// decodeLLVMAttributesForBitcode - This returns an attribute bitset containing
145 /// the LLVM attributes that have been decoded from the given integer. This
146 /// function must stay in sync with 'encodeLLVMAttributesForBitcode'.
147 Attribute Attribute::decodeLLVMAttributesForBitcode(LLVMContext &C,
148 uint64_t EncodedAttrs) {
149 // The alignment is stored as a 16-bit raw value from bits 31--16. We shift
150 // the bits above 31 down by 11 bits.
151 unsigned Alignment = (EncodedAttrs & (0xffffULL << 16)) >> 16;
152 assert((!Alignment || isPowerOf2_32(Alignment)) &&
153 "Alignment must be a power of two.");
154
155 AttrBuilder B(EncodedAttrs & 0xffff);
156 if (Alignment)
157 B.addAlignmentAttr(Alignment);
158 B.addRawValue((EncodedAttrs & (0xffffULL << 32)) >> 11);
159 return Attribute::get(C, B);
160103 }
161104
162105 std::string Attribute::getAsString() const {
665608 return get(C, AttributeWithIndex::get(Idx, Attribute::get(C, Kind)));
666609 }
667610
611 AttributeSet AttributeSet::get(LLVMContext &C, ArrayRef Attrs) {
612 SmallVector AttrList;
613 for (ArrayRef::iterator I = Attrs.begin(), E = Attrs.end();
614 I != E; ++I) {
615 AttributeSet AS = *I;
616 if (!AS.AttrList) continue;
617 AttrList.append(AS.AttrList->AttrList.begin(), AS.AttrList->AttrList.end());
618 }
619
620 return get(C, AttrList);
621 }
622
668623 //===----------------------------------------------------------------------===//
669624 // AttributeSet Method Implementations
670625 //===----------------------------------------------------------------------===//
685640 assert(AttrList && Slot < AttrList->getNumAttributes() &&
686641 "Slot # out of range!");
687642 return AttrList->getSlotIndex(Slot);
643 }
644
645 AttributeSet AttributeSet::getSlotAttributes(unsigned Slot) const {
646 assert(AttrList && Slot < AttrList->getNumAttributes() &&
647 "Slot # out of range!");
648 return AttrList->getSlotAttributes(Slot);
688649 }
689650
690651 /// getSlot - Return the AttributeWithIndex at the specified slot. This
858819
859820 dbgs() << "]\n";
860821 }
822
823 //===----------------------------------------------------------------------===//
824 // AttributeFuncs Function Defintions
825 //===----------------------------------------------------------------------===//
826
827 Attribute AttributeFuncs::typeIncompatible(Type *Ty) {
828 AttrBuilder Incompatible;
829
830 if (!Ty->isIntegerTy())
831 // Attribute that only apply to integers.
832 Incompatible.addAttribute(Attribute::SExt)
833 .addAttribute(Attribute::ZExt);
834
835 if (!Ty->isPointerTy())
836 // Attribute that only apply to pointers.
837 Incompatible.addAttribute(Attribute::ByVal)
838 .addAttribute(Attribute::Nest)
839 .addAttribute(Attribute::NoAlias)
840 .addAttribute(Attribute::NoCapture)
841 .addAttribute(Attribute::StructRet);
842
843 return Attribute::get(Ty->getContext(), Incompatible);
844 }
845
846 /// encodeLLVMAttributesForBitcode - This returns an integer containing an
847 /// encoding of all the LLVM attributes found in the given attribute bitset.
848 /// Any change to this encoding is a breaking change to bitcode compatibility.
849 uint64_t AttributeFuncs::encodeLLVMAttributesForBitcode(AttributeSet Attrs,
850 unsigned Index) {
851 // FIXME: It doesn't make sense to store the alignment information as an
852 // expanded out value, we should store it as a log2 value. However, we can't
853 // just change that here without breaking bitcode compatibility. If this ever
854 // becomes a problem in practice, we should introduce new tag numbers in the
855 // bitcode file and have those tags use a more efficiently encoded alignment
856 // field.
857
858 // Store the alignment in the bitcode as a 16-bit raw value instead of a 5-bit
859 // log2 encoded value. Shift the bits above the alignment up by 11 bits.
860 uint64_t EncodedAttrs = Attrs.Raw(Index) & 0xffff;
861 if (Attrs.hasAttribute(Index, Attribute::Alignment))
862 EncodedAttrs |= Attrs.getParamAlignment(Index) << 16;
863 EncodedAttrs |= (Attrs.Raw(Index) & (0xffffULL << 21)) << 11;
864 return EncodedAttrs;
865 }
866
867 /// decodeLLVMAttributesForBitcode - This returns an attribute bitset containing
868 /// the LLVM attributes that have been decoded from the given integer. This
869 /// function must stay in sync with 'encodeLLVMAttributesForBitcode'.
870 Attribute AttributeFuncs::decodeLLVMAttributesForBitcode(LLVMContext &C,
871 uint64_t EncodedAttrs){
872 // The alignment is stored as a 16-bit raw value from bits 31--16. We shift
873 // the bits above 31 down by 11 bits.
874 unsigned Alignment = (EncodedAttrs & (0xffffULL << 16)) >> 16;
875 assert((!Alignment || isPowerOf2_32(Alignment)) &&
876 "Alignment must be a power of two.");
877
878 AttrBuilder B(EncodedAttrs & 0xffff);
879 if (Alignment)
880 B.addAlignmentAttr(Alignment);
881 B.addRawValue((EncodedAttrs & (0xffffULL << 32)) >> 11);
882 return Attribute::get(C, B);
883 }
884
692692 "'noinline and alwaysinline' are incompatible!", V);
693693
694694 Assert1(!AttrBuilder(Attrs, Idx).
695 hasAttributes(Attribute::typeIncompatible(Ty)),
695 hasAttributes(AttributeFuncs::typeIncompatible(Ty)),
696696 "Wrong types for attribute: " +
697 Attribute::typeIncompatible(Ty).getAsString(), V);
697 AttributeFuncs::typeIncompatible(Ty).getAsString(), V);
698698
699699 if (PointerType *PTy = dyn_cast(Ty))
700700 Assert1(!Attrs.hasAttribute(Idx, Attribute::ByVal) ||
473473 Out << "AttributeWithIndex PAWI;"; nl(Out);
474474 for (unsigned i = 0; i < PAL.getNumSlots(); ++i) {
475475 unsigned index = PAL.getSlotIndex(i);
476 AttrBuilder attrs(PAL.getSlot(i).Attrs);
476 AttrBuilder attrs(PAL.getSlotAttributes(i), index);
477477 Out << "PAWI.Index = " << index << "U;\n";
478478 Out << " {\n AttrBuilder B;\n";
479479
272272 // Drop any attributes that were on the vararg arguments.
273273 AttributeSet PAL = CS.getAttributes();
274274 if (!PAL.isEmpty() && PAL.getSlotIndex(PAL.getNumSlots() - 1) > NumArgs) {
275 SmallVectorWithIndex, 8> AttributesVec;
275 SmallVectorSet, 8> AttributesVec;
276276 for (unsigned i = 0; PAL.getSlotIndex(i) <= NumArgs; ++i)
277 AttributesVec.push_back(PAL.getSlot(i));
277 AttributesVec.push_back(PAL.getSlotAttributes(i));
278278 if (PAL.hasAttributes(AttributeSet::FunctionIndex))
279 AttributesVec.push_back(AttributeWithIndex::get(Fn.getContext(),
280 AttributeSet::FunctionIndex,
281 PAL.getFnAttributes()));
279 AttributesVec.push_back(
280 AttributeSet::get(Fn.getContext(),
281 AttributeWithIndex::get(Fn.getContext(),
282 AttributeSet::FunctionIndex,
283 PAL.getFnAttributes())));
282284 PAL = AttributeSet::get(Fn.getContext(), AttributesVec);
283285 }
284286
764766 RAttrs =
765767 AttributeSet::get(NRetTy->getContext(), AttributeSet::ReturnIndex,
766768 AttrBuilder(RAttrs, AttributeSet::ReturnIndex).
767 removeAttributes(Attribute::typeIncompatible(NRetTy)));
769 removeAttributes(AttributeFuncs::typeIncompatible(NRetTy)));
768770 else
769771 assert(!AttrBuilder(RAttrs, AttributeSet::ReturnIndex).
770 hasAttributes(Attribute::typeIncompatible(NRetTy)) &&
772 hasAttributes(AttributeFuncs::typeIncompatible(NRetTy)) &&
771773 "Return attributes no longer compatible?");
772774
773775 if (RAttrs.hasAttributes(AttributeSet::ReturnIndex))
845847 RAttrs =
846848 AttributeSet::get(NF->getContext(), AttributeSet::ReturnIndex,
847849 AttrBuilder(RAttrs, AttributeSet::ReturnIndex).
848 removeAttributes(Attribute::typeIncompatible(NF->getReturnType())));
850 removeAttributes(AttributeFuncs::typeIncompatible(NF->getReturnType())));
849851 if (RAttrs.hasAttributes(AttributeSet::ReturnIndex))
850852 AttributesVec.push_back(AttributeWithIndex::get(NF->getContext(),
851853 AttributeSet::ReturnIndex,
20672067
20682068 static AttributeSet StripNest(LLVMContext &C, const AttributeSet &Attrs) {
20692069 for (unsigned i = 0, e = Attrs.getNumSlots(); i != e; ++i) {
2070 if (!Attrs.getSlot(i).Attrs.hasAttribute(Attribute::Nest))
2070 unsigned Index = Attrs.getSlotIndex(i);
2071 if (!Attrs.getSlotAttributes(i).hasAttribute(Index, Attribute::Nest))
20712072 continue;
20722073
20732074 // There can be only one.
2074 return Attrs.removeAttribute(C, Attrs.getSlotIndex(i), Attribute::Nest);
2075 return Attrs.removeAttribute(C, Index, Attribute::Nest);
20752076 }
20762077
20772078 return Attrs;
10141014
10151015 if (!CallerPAL.isEmpty() && !Caller->use_empty()) {
10161016 AttrBuilder RAttrs(CallerPAL, AttributeSet::ReturnIndex);
1017 if (RAttrs.hasAttributes(Attribute::typeIncompatible(NewRetTy)))
1017 if (RAttrs.hasAttributes(AttributeFuncs::typeIncompatible(NewRetTy)))
10181018 return false; // Attribute not compatible with transformed value.
10191019 }
10201020
10441044 return false; // Cannot transform this parameter value.
10451045
10461046 if (AttrBuilder(CallerPAL.getParamAttributes(i + 1), i + 1).
1047 hasAttributes(Attribute::typeIncompatible(ParamTy)))
1047 hasAttributes(AttributeFuncs::typeIncompatible(ParamTy)))
10481048 return false; // Attribute not compatible with transformed value.
10491049
10501050 // If the parameter is passed as a byval argument, then we have to have a
11001100 // won't be dropping them. Check that these extra arguments have attributes
11011101 // that are compatible with being a vararg call argument.
11021102 for (unsigned i = CallerPAL.getNumSlots(); i; --i) {
1103 if (CallerPAL.getSlotIndex(i - 1) <= FT->getNumParams())
1103 unsigned Index = CallerPAL.getSlotIndex(i - 1);
1104 if (Index <= FT->getNumParams())
11041105 break;
1105 Attribute PAttrs = CallerPAL.getSlot(i - 1).Attrs;
1106
11061107 // Check if it has an attribute that's incompatible with varargs.
1107 if (PAttrs.hasAttribute(Attribute::StructRet))
1108 AttributeSet PAttrs = CallerPAL.getSlotAttributes(i - 1);
1109 if (PAttrs.hasAttribute(Index, Attribute::StructRet))
11081110 return false;
11091111 }
11101112
11211123
11221124 // If the return value is not being used, the type may not be compatible
11231125 // with the existing attributes. Wipe out any problematic attributes.
1124 RAttrs.removeAttributes(Attribute::typeIncompatible(NewRetTy));
1126 RAttrs.removeAttributes(AttributeFuncs::typeIncompatible(NewRetTy));
11251127
11261128 // Add the new return attributes.
11271129 if (RAttrs.hasAttributes())