Lines Matching full:attribute

10 // This file implements the Attribute, AttributeImpl, AttrBuilder,
49 // Attribute Construction Methods
94 Attribute Attribute::get(LLVMContext &Context, Attribute::AttrKind Kind,
96 bool IsIntAttr = Attribute::isIntAttrKind(Kind);
97 assert((IsIntAttr || Attribute::isEnumAttrKind(Kind)) &&
98 "Not an enum or int attribute");
121 // Return the Attribute that we found or created.
122 return Attribute(PA);
125 Attribute Attribute::get(LLVMContext &Context, StringRef Kind, StringRef Val) {
144 // Return the Attribute that we found or created.
145 return Attribute(PA);
148 Attribute Attribute::get(LLVMContext &Context, Attribute::AttrKind Kind,
150 assert(Attribute::isTypeAttrKind(Kind) && "Not a type attribute");
166 // Return the Attribute that we found or created.
167 return Attribute(PA);
170 Attribute Attribute::get(LLVMContext &Context, Attribute::AttrKind Kind,
172 assert(Attribute::isConstantRangeAttrKind(Kind) &&
173 "Not a ConstantRange attribute");
191 // Return the Attribute that we found or created.
192 return Attribute(PA);
195 Attribute Attribute::get(LLVMContext &Context, Attribute::AttrKind Kind,
197 assert(Attribute::isConstantRangeListAttrKind(Kind) &&
198 "Not a ConstantRangeList attribute");
228 // Return the Attribute that we found or created.
229 return Attribute(PA);
232 Attribute Attribute::getWithAlignment(LLVMContext &Context, Align A) {
237 Attribute Attribute::getWithStackAlignment(LLVMContext &Context, Align A) {
242 Attribute Attribute::getWithDereferenceableBytes(LLVMContext &Context,
248 Attribute Attribute::getWithDereferenceableOrNullBytes(LLVMContext &Context,
254 Attribute Attribute::getWithByValType(LLVMContext &Context, Type *Ty) {
258 Attribute Attribute::getWithStructRetType(LLVMContext &Context, Type *Ty) {
262 Attribute Attribute::getWithByRefType(LLVMContext &Context, Type *Ty) {
266 Attribute Attribute::getWithPreallocatedType(LLVMContext &Context, Type *Ty) {
270 Attribute Attribute::getWithInAllocaType(LLVMContext &Context, Type *Ty) {
274 Attribute Attribute::getWithUWTableKind(LLVMContext &Context,
279 Attribute Attribute::getWithMemoryEffects(LLVMContext &Context,
284 Attribute Attribute::getWithNoFPClass(LLVMContext &Context,
289 Attribute
290 Attribute::getWithAllocSizeArgs(LLVMContext &Context, unsigned ElemSizeArg,
297 Attribute Attribute::getWithVScaleRangeArgs(LLVMContext &Context,
303 Attribute::AttrKind Attribute::getAttrKindFromName(StringRef AttrName) {
304 return StringSwitch<Attribute::AttrKind>(AttrName)
307 .Case(#DISPLAY_NAME, Attribute::ENUM_NAME)
309 .Default(Attribute::None);
312 StringRef Attribute::getNameFromAttrKind(Attribute::AttrKind AttrKind) {
316 case Attribute::ENUM_NAME: \
319 case Attribute::None:
326 bool Attribute::isExistingAttribute(StringRef Name) {
335 // Attribute Accessor Methods
338 bool Attribute::isEnumAttribute() const {
342 bool Attribute::isIntAttribute() const {
346 bool Attribute::isStringAttribute() const {
350 bool Attribute::isTypeAttribute() const {
354 bool Attribute::isConstantRangeAttribute() const {
358 bool Attribute::isConstantRangeListAttribute() const {
362 Attribute::AttrKind Attribute::getKindAsEnum() const {
366 "Invalid attribute type to get the kind as an enum!");
370 uint64_t Attribute::getValueAsInt() const {
373 "Expected the attribute to be an integer attribute!");
377 bool Attribute::getValueAsBool() const {
380 "Expected the attribute to be a string attribute!");
384 StringRef Attribute::getKindAsString() const {
387 "Invalid attribute type to get the kind as a string!");
391 StringRef Attribute::getValueAsString() const {
394 "Invalid attribute type to get the value as a string!");
398 Type *Attribute::getValueAsType() const {
401 "Invalid attribute type to get the value as a type!");
405 const ConstantRange &Attribute::getValueAsConstantRange() const {
407 "Invalid attribute type to get the value as a ConstantRange!");
411 ArrayRef<ConstantRange> Attribute::getValueAsConstantRangeList() const {
413 "Invalid attribute type to get the value as a ConstantRangeList!");
417 bool Attribute::hasAttribute(AttrKind Kind) const {
421 bool Attribute::hasAttribute(StringRef Kind) const {
426 MaybeAlign Attribute::getAlignment() const {
427 assert(hasAttribute(Attribute::Alignment) &&
428 "Trying to get alignment from non-alignment attribute!");
432 MaybeAlign Attribute::getStackAlignment() const {
433 assert(hasAttribute(Attribute::StackAlignment) &&
434 "Trying to get alignment from non-alignment attribute!");
438 uint64_t Attribute::getDereferenceableBytes() const {
439 assert(hasAttribute(Attribute::Dereferenceable) &&
441 "non-dereferenceable attribute!");
445 uint64_t Attribute::getDereferenceableOrNullBytes() const {
446 assert(hasAttribute(Attribute::DereferenceableOrNull) &&
448 "non-dereferenceable attribute!");
453 Attribute::getAllocSizeArgs() const {
454 assert(hasAttribute(Attribute::AllocSize) &&
455 "Trying to get allocsize args from non-allocsize attribute");
459 unsigned Attribute::getVScaleRangeMin() const {
460 assert(hasAttribute(Attribute::VScaleRange) &&
461 "Trying to get vscale args from non-vscale attribute");
465 std::optional<unsigned> Attribute::getVScaleRangeMax() const {
466 assert(hasAttribute(Attribute::VScaleRange) &&
467 "Trying to get vscale args from non-vscale attribute");
471 UWTableKind Attribute::getUWTableKind() const {
472 assert(hasAttribute(Attribute::UWTable) &&
473 "Trying to get unwind table kind from non-uwtable attribute");
477 AllocFnKind Attribute::getAllocKind() const {
478 assert(hasAttribute(Attribute::AllocKind) &&
479 "Trying to get allockind value from non-allockind attribute");
483 MemoryEffects Attribute::getMemoryEffects() const {
484 assert(hasAttribute(Attribute::Memory) &&
485 "Can only call getMemoryEffects() on memory attribute");
489 FPClassTest Attribute::getNoFPClass() const {
490 assert(hasAttribute(Attribute::NoFPClass) &&
491 "Can only call getNoFPClass() on nofpclass attribute");
495 const ConstantRange &Attribute::getRange() const {
496 assert(hasAttribute(Attribute::Range) &&
497 "Trying to get range args from non-range attribute");
501 ArrayRef<ConstantRange> Attribute::getInitializes() const {
502 assert(hasAttribute(Attribute::Initializes) &&
503 "Trying to get initializes attr from non-ConstantRangeList attribute");
521 std::string Attribute::getAsString(bool InAttrGrp) const {
542 if (hasAttribute(Attribute::Alignment))
553 if (hasAttribute(Attribute::StackAlignment))
556 if (hasAttribute(Attribute::Dereferenceable))
559 if (hasAttribute(Attribute::DereferenceableOrNull))
562 if (hasAttribute(Attribute::AllocSize)) {
573 if (hasAttribute(Attribute::VScaleRange)) {
581 if (hasAttribute(Attribute::UWTable)) {
583 assert(Kind != UWTableKind::None && "uwtable attribute should not be none");
587 if (hasAttribute(Attribute::AllocKind)) {
607 if (hasAttribute(Attribute::Memory)) {
649 if (hasAttribute(Attribute::NoFPClass)) {
656 if (hasAttribute(Attribute::Range)) {
668 if (hasAttribute(Attribute::Initializes)) {
690 // Since some attribute strings contain special characters that cannot be
691 // printable, those have to be escaped to make the attribute value
703 llvm_unreachable("Unknown attribute");
706 bool Attribute::hasParentContext(LLVMContext &C) const {
707 assert(isValid() && "invalid Attribute doesn't refer to any context");
714 bool Attribute::operator<(Attribute A) const {
721 void Attribute::Profile(FoldingSetNodeID &ID) const {
734 static bool hasAttributeProperty(Attribute::AttrKind Kind,
737 assert(Index < std::size(AttrPropTable) && "Invalid attribute kind");
741 bool Attribute::canUseAsFnAttr(AttrKind Kind) {
745 bool Attribute::canUseAsParamAttr(AttrKind Kind) {
749 bool Attribute::canUseAsRetAttr(AttrKind Kind) {
757 bool AttributeImpl::hasAttribute(Attribute::AttrKind A) const {
767 Attribute::AttrKind AttributeImpl::getKindAsEnum() const {
814 // This sorts the attributes with Attribute::AttrKinds coming first (sorted
821 assert(!AI.isEnumAttribute() && "Non-unique attribute");
846 AttributeSet AttributeSet::get(LLVMContext &C, ArrayRef<Attribute> Attrs) {
851 Attribute::AttrKind Kind) const {
879 Attribute::AttrKind Kind) const {
909 bool AttributeSet::hasAttribute(Attribute::AttrKind Kind) const {
917 Attribute AttributeSet::getAttribute(Attribute::AttrKind Kind) const {
918 return SetNode ? SetNode->getAttribute(Kind) : Attribute();
921 Attribute AttributeSet::getAttribute(StringRef Kind) const {
922 return SetNode ? SetNode->getAttribute(Kind) : Attribute();
942 return SetNode ? SetNode->getAttributeType(Attribute::ByRef) : nullptr;
946 return SetNode ? SetNode->getAttributeType(Attribute::ByVal) : nullptr;
950 return SetNode ? SetNode->getAttributeType(Attribute::StructRet) : nullptr;
954 return SetNode ? SetNode->getAttributeType(Attribute::Preallocated) : nullptr;
958 return SetNode ? SetNode->getAttributeType(Attribute::InAlloca) : nullptr;
962 return SetNode ? SetNode->getAttributeType(Attribute::ElementType) : nullptr;
1028 AttributeSetNode::AttributeSetNode(ArrayRef<Attribute> Attrs)
1031 llvm::copy(Attrs, getTrailingObjects<Attribute>());
1042 ArrayRef<Attribute> Attrs) {
1043 SmallVector<Attribute, 8> SortedAttrs(Attrs.begin(), Attrs.end());
1049 ArrayRef<Attribute> SortedAttrs) {
1069 void *Mem = ::operator new(totalSizeToAlloc<Attribute>(SortedAttrs.size()));
1086 std::optional<Attribute>
1087 AttributeSetNode::findEnumAttribute(Attribute::AttrKind Kind) const {
1094 const Attribute *I =
1096 [](Attribute A, Attribute::AttrKind Kind) {
1103 Attribute AttributeSetNode::getAttribute(Attribute::AttrKind Kind) const {
1109 Attribute AttributeSetNode::getAttribute(StringRef Kind) const {
1114 if (auto A = findEnumAttribute(Attribute::Alignment))
1120 if (auto A = findEnumAttribute(Attribute::StackAlignment))
1125 Type *AttributeSetNode::getAttributeType(Attribute::AttrKind Kind) const {
1132 if (auto A = findEnumAttribute(Attribute::Dereferenceable))
1138 if (auto A = findEnumAttribute(Attribute::DereferenceableOrNull))
1145 if (auto A = findEnumAttribute(Attribute::AllocSize))
1151 if (auto A = findEnumAttribute(Attribute::VScaleRange))
1157 if (auto A = findEnumAttribute(Attribute::VScaleRange))
1163 if (auto A = findEnumAttribute(Attribute::UWTable))
1169 if (auto A = findEnumAttribute(Attribute::AllocKind))
1175 if (auto A = findEnumAttribute(Attribute::Memory))
1181 if (auto A = findEnumAttribute(Attribute::NoFPClass))
1235 bool AttributeListImpl::hasAttrSomewhere(Attribute::AttrKind Kind,
1292 ArrayRef<std::pair<unsigned, Attribute>> Attrs) {
1300 [](const std::pair<unsigned, Attribute> &Pair) {
1303 "Pointless attribute!");
1308 for (ArrayRef<std::pair<unsigned, Attribute>>::iterator I = Attrs.begin(),
1311 SmallVector<Attribute, 4> AttrVec;
1336 "Pointless attribute!");
1356 // AttributeListImpls by dropping empty attribute sets at the end of the list.
1373 // If all attribute sets were empty, we can use the empty attribute list.
1384 // Drop the empty argument attribute sets at the end.
1408 ArrayRef<Attribute::AttrKind> Kinds) {
1409 SmallVector<std::pair<unsigned, Attribute>, 8> Attrs;
1411 Attrs.emplace_back(Index, Attribute::get(C, K));
1416 ArrayRef<Attribute::AttrKind> Kinds,
1418 assert(Kinds.size() == Values.size() && "Mismatched attribute values.");
1419 SmallVector<std::pair<unsigned, Attribute>, 8> Attrs;
1422 Attrs.emplace_back(Index, Attribute::get(C, K, *VI++));
1428 SmallVector<std::pair<unsigned, Attribute>, 8> Attrs;
1430 Attrs.emplace_back(Index, Attribute::get(C, K));
1462 Attribute::AttrKind Kind) const {
1467 SmallVector<Attribute, 8> NewAttrs(Attrs.begin(), Attrs.end());
1468 NewAttrs.push_back(Attribute::get(C, Kind));
1481 Attribute A) const {
1496 // Remove trailing empty attribute sets.
1520 Attribute A) const {
1540 Attribute::AttrKind Kind) const {
1633 Attribute::AttrKind Kind) const {
1645 bool AttributeList::hasFnAttr(Attribute::AttrKind Kind) const {
1653 bool AttributeList::hasAttrSomewhere(Attribute::AttrKind Attr,
1658 Attribute AttributeList::getAttributeAtIndex(unsigned Index,
1659 Attribute::AttrKind Kind) const {
1663 Attribute AttributeList::getAttributeAtIndex(unsigned Index,
1761 assert(!isEmpty() && "an empty attribute list has no parent context");
1822 /// Attribute comparator that only compares attribute keys. Enum attributes are
1825 bool operator()(Attribute A0, Attribute A1) const {
1838 bool operator()(Attribute A0, Attribute::AttrKind Kind) const {
1843 bool operator()(Attribute A0, StringRef Kind) const {
1851 static void addAttributeImpl(SmallVectorImpl<Attribute> &Attrs, K Kind,
1852 Attribute Attr) {
1860 AttrBuilder &AttrBuilder::addAttribute(Attribute Attr) {
1868 AttrBuilder &AttrBuilder::addAttribute(Attribute::AttrKind Kind) {
1869 addAttributeImpl(Attrs, Kind, Attribute::get(Ctx, Kind));
1874 addAttributeImpl(Attrs, A, Attribute::get(Ctx, A, V));
1878 AttrBuilder &AttrBuilder::removeAttribute(Attribute::AttrKind Val) {
1879 assert((unsigned)Val < Attribute::EndAttrKinds && "Attribute out of range!");
1894 AttrBuilder::getRawIntAttr(Attribute::AttrKind Kind) const {
1895 assert(Attribute::isIntAttrKind(Kind) && "Not an int attribute");
1896 Attribute A = getAttribute(Kind);
1902 AttrBuilder &AttrBuilder::addRawIntAttr(Attribute::AttrKind Kind,
1904 return addAttribute(Attribute::get(Ctx, Kind, Value));
1909 Attribute A = getAttribute(Attribute::AllocSize);
1920 return addRawIntAttr(Attribute::Alignment, Align->value());
1929 return addRawIntAttr(Attribute::StackAlignment, Align->value());
1935 return addRawIntAttr(Attribute::Dereferenceable, Bytes);
1942 return addRawIntAttr(Attribute::DereferenceableOrNull, Bytes);
1954 return addRawIntAttr(Attribute::AllocSize, RawArgs);
1967 return addRawIntAttr(Attribute::VScaleRange, RawArgs);
1973 return addRawIntAttr(Attribute::UWTable, uint64_t(Kind));
1977 return addRawIntAttr(Attribute::Memory, ME.toIntValue());
1984 return addRawIntAttr(Attribute::NoFPClass, Mask);
1988 return addRawIntAttr(Attribute::AllocKind, static_cast<uint64_t>(Kind));
1991 Type *AttrBuilder::getTypeAttr(Attribute::AttrKind Kind) const {
1992 assert(Attribute::isTypeAttrKind(Kind) && "Not a type attribute");
1993 Attribute A = getAttribute(Kind);
1997 AttrBuilder &AttrBuilder::addTypeAttr(Attribute::AttrKind Kind, Type *Ty) {
1998 return addAttribute(Attribute::get(Ctx, Kind, Ty));
2002 return addTypeAttr(Attribute::ByVal, Ty);
2006 return addTypeAttr(Attribute::StructRet, Ty);
2010 return addTypeAttr(Attribute::ByRef, Ty);
2014 return addTypeAttr(Attribute::Preallocated, Ty);
2018 return addTypeAttr(Attribute::InAlloca, Ty);
2021 AttrBuilder &AttrBuilder::addConstantRangeAttr(Attribute::AttrKind Kind,
2023 return addAttribute(Attribute::get(Ctx, Kind, CR));
2027 return addConstantRangeAttr(Attribute::Range, CR);
2031 AttrBuilder::addConstantRangeListAttr(Attribute::AttrKind Kind,
2033 return addAttribute(Attribute::get(Ctx, Kind, Val));
2037 return addConstantRangeListAttr(Attribute::Initializes, CRL.rangesRef());
2049 erase_if(Attrs, [&](Attribute A) { return AM.contains(A); });
2054 return any_of(Attrs, [&](Attribute A) { return AM.contains(A); });
2057 Attribute AttrBuilder::getAttribute(Attribute::AttrKind A) const {
2058 assert((unsigned)A < Attribute::EndAttrKinds && "Attribute out of range!");
2065 Attribute AttrBuilder::getAttribute(StringRef A) const {
2072 bool AttrBuilder::contains(Attribute::AttrKind A) const {
2088 /// Returns true if this is a type legal for the 'nofpclass' attribute. This
2106 Incompatible.addAttribute(Attribute::AllocAlign);
2108 Incompatible.addAttribute(Attribute::SExt).addAttribute(Attribute::ZExt);
2114 Incompatible.addAttribute(Attribute::Range);
2120 Incompatible.addAttribute(Attribute::NoAlias)
2121 .addAttribute(Attribute::NoCapture)
2122 .addAttribute(Attribute::NonNull)
2123 .addAttribute(Attribute::ReadNone)
2124 .addAttribute(Attribute::ReadOnly)
2125 .addAttribute(Attribute::Dereferenceable)
2126 .addAttribute(Attribute::DereferenceableOrNull)
2127 .addAttribute(Attribute::Writable)
2128 .addAttribute(Attribute::DeadOnUnwind)
2129 .addAttribute(Attribute::Initializes);
2131 Incompatible.addAttribute(Attribute::Nest)
2132 .addAttribute(Attribute::SwiftError)
2133 .addAttribute(Attribute::Preallocated)
2134 .addAttribute(Attribute::InAlloca)
2135 .addAttribute(Attribute::ByVal)
2136 .addAttribute(Attribute::StructRet)
2137 .addAttribute(Attribute::ByRef)
2138 .addAttribute(Attribute::ElementType)
2139 .addAttribute(Attribute::AllocatedPointer);
2145 Incompatible.addAttribute(Attribute::Alignment);
2150 Incompatible.addAttribute(Attribute::NoFPClass);
2156 Incompatible.addAttribute(Attribute::NoUndef);
2164 AM.addAttribute(Attribute::NoUndef);
2165 AM.addAttribute(Attribute::Dereferenceable);
2166 AM.addAttribute(Attribute::DereferenceableOrNull);
2208 return !Callee.getAttributes().hasFnAttr(Attribute::StrictFP) ||
2209 Caller.getAttributes().hasFnAttr(Attribute::StrictFP);
2226 /// This function sets the caller's attribute to false if the callee's attribute
2238 /// This function sets the caller's attribute to true if the callee's attribute
2251 // with Clang's -fno-stack-protector or no_stack_protector attribute), don't
2256 // If upgrading the SSP attribute, clear out the old SSP Attributes first.
2260 OldSSPAttr.addAttribute(Attribute::StackProtect)
2261 .addAttribute(Attribute::StackProtectStrong)
2262 .addAttribute(Attribute::StackProtectReq);
2264 if (Callee.hasFnAttribute(Attribute::StackProtectReq)) {
2266 Caller.addFnAttr(Attribute::StackProtectReq);
2267 } else if (Callee.hasFnAttribute(Attribute::StackProtectStrong) &&
2268 !Caller.hasFnAttribute(Attribute::StackProtectReq)) {
2270 Caller.addFnAttr(Attribute::StackProtectStrong);
2271 } else if (Callee.hasFnAttribute(Attribute::StackProtect) &&
2272 !Caller.hasFnAttribute(Attribute::StackProtectReq) &&
2273 !Caller.hasFnAttribute(Attribute::StackProtectStrong))
2274 Caller.addFnAttr(Attribute::StackProtect);
2291 Attribute CalleeAttr = Callee.getFnAttribute("stack-probe-size");
2293 Attribute CallerAttr = Caller.getFnAttribute("stack-probe-size");
2310 /// caller has the attribute, but the callee doesn't, we need to remove the
2311 /// attribute from the caller since we can't make any guarantees about the
2314 /// to merge the attribute this way. Heuristics that would use
2319 Attribute CallerAttr = Caller.getFnAttribute("min-legal-vector-width");
2321 Attribute CalleeAttr = Callee.getFnAttribute("min-legal-vector-width");
2329 // If the callee doesn't have the attribute then we don't know anything
2330 // and must drop the attribute from the caller.
2336 /// If the inlined function has null_pointer_is_valid attribute,
2337 /// set this attribute in the caller post inlining.
2341 Caller.addFnAttr(Attribute::NullPointerIsValid);
2347 Attribute::AttrKind Kind) {
2352 Attribute::AttrKind Kind, bool Val) {
2376 static enum Attribute::AttrKind getKind() { \
2377 return llvm::Attribute::ENUM_NAME; \
2419 Attribute Attr = Fn.getFnAttribute("min-legal-vector-width");