25#include "llvm/Config/llvm-config.h"
62 const std::optional<unsigned> &NumElemsArg) {
64 "Attempting to pack a reserved value");
70static std::pair<unsigned, std::optional<unsigned>>
72 unsigned NumElems = Num & std::numeric_limits<unsigned>::max();
73 unsigned ElemSizeArg = Num >> 32;
75 std::optional<unsigned> NumElemsArg;
77 NumElemsArg = NumElems;
78 return std::make_pair(ElemSizeArg, NumElemsArg);
82 std::optional<unsigned> MaxValue) {
83 return uint64_t(MinValue) << 32 | MaxValue.value_or(0);
86static std::pair<unsigned, std::optional<unsigned>>
88 unsigned MaxValue =
Value & std::numeric_limits<unsigned>::max();
89 unsigned MinValue =
Value >> 32;
91 return std::make_pair(MinValue,
92 MaxValue > 0 ? MaxValue : std::optional<unsigned>());
99 "Not an enum or int attribute");
107 assert(Val == 0 &&
"Value must be zero for enum attributes");
110 AttributeImpl *PA = pImpl->AttrsSet.FindNodeOrInsertPos(
ID, InsertPoint);
119 pImpl->AttrsSet.InsertNode(PA, InsertPoint);
130 if (!Val.
empty())
ID.AddString(Val);
133 AttributeImpl *PA = pImpl->AttrsSet.FindNodeOrInsertPos(
ID, InsertPoint);
142 pImpl->AttrsSet.InsertNode(PA, InsertPoint);
158 AttributeImpl *PA = pImpl->AttrsSet.FindNodeOrInsertPos(
ID, InsertPoint);
164 pImpl->AttrsSet.InsertNode(PA, InsertPoint);
174 "Not a ConstantRange attribute");
183 AttributeImpl *PA = pImpl->AttrsSet.FindNodeOrInsertPos(
ID, InsertPoint);
188 PA =
new (pImpl->ConstantRangeAttributeAlloc.Allocate())
190 pImpl->AttrsSet.InsertNode(PA, InsertPoint);
200 "Not a ConstantRangeList attribute");
204 ID.AddInteger(Val.
size());
205 for (
auto &CR : Val) {
206 CR.getLower().Profile(
ID);
207 CR.getUpper().Profile(
ID);
211 AttributeImpl *PA = pImpl->AttrsSet.FindNodeOrInsertPos(
ID, InsertPoint);
221 void *Mem = pImpl->Alloc.Allocate(
225 pImpl->AttrsSet.InsertNode(PA, InsertPoint);
226 pImpl->ConstantRangeListAttributes.push_back(
236 return get(Context, Alignment,
A.value());
240 assert(
A <= 0x100 &&
"Alignment too large.");
241 return get(Context, StackAlignment,
A.value());
246 assert(Bytes &&
"Bytes must be non-zero.");
247 return get(Context, Dereferenceable, Bytes);
252 assert(Bytes &&
"Bytes must be non-zero.");
253 return get(Context, DereferenceableOrNull, Bytes);
257 return get(Context, ByVal, Ty);
261 return get(Context, StructRet, Ty);
265 return get(Context, ByRef, Ty);
269 return get(Context, Preallocated, Ty);
273 return get(Context, InAlloca, Ty);
288 return get(Context, NoFPClass, ClassMask);
297 const std::optional<unsigned> &NumElemsArg) {
298 assert(!(ElemSizeArg == 0 && NumElemsArg == 0) &&
299 "Invalid allocsize arguments -- given allocsize(0, 0)");
304 return get(Context, AllocKind,
static_cast<uint64_t>(Kind));
315#define GET_ATTR_NAMES
316#define ATTRIBUTE_ENUM(ENUM_NAME, DISPLAY_NAME) \
317 .Case(#DISPLAY_NAME, Attribute::ENUM_NAME)
318#include "llvm/IR/Attributes.inc"
324#define GET_ATTR_NAMES
325#define ATTRIBUTE_ENUM(ENUM_NAME, DISPLAY_NAME) \
326 case Attribute::ENUM_NAME: \
327 return #DISPLAY_NAME;
328#include "llvm/IR/Attributes.inc"
338#define GET_ATTR_NAMES
339#define ATTRIBUTE_ALL(ENUM_NAME, DISPLAY_NAME) .Case(#DISPLAY_NAME, true)
340#include "llvm/IR/Attributes.inc"
349 return pImpl && pImpl->isEnumAttribute();
353 return pImpl && pImpl->isIntAttribute();
357 return pImpl && pImpl->isStringAttribute();
361 return pImpl && pImpl->isTypeAttribute();
365 return pImpl && pImpl->isConstantRangeAttribute();
369 return pImpl && pImpl->isConstantRangeListAttribute();
373 if (!pImpl)
return None;
375 "Invalid attribute type to get the kind as an enum!");
376 return pImpl->getKindAsEnum();
380 if (!pImpl)
return 0;
382 "Expected the attribute to be an integer attribute!");
383 return pImpl->getValueAsInt();
387 if (!pImpl)
return false;
389 "Expected the attribute to be a string attribute!");
390 return pImpl->getValueAsBool();
394 if (!pImpl)
return {};
396 "Invalid attribute type to get the kind as a string!");
397 return pImpl->getKindAsString();
401 if (!pImpl)
return {};
403 "Invalid attribute type to get the value as a string!");
404 return pImpl->getValueAsString();
408 if (!pImpl)
return {};
410 "Invalid attribute type to get the value as a type!");
411 return pImpl->getValueAsType();
416 "Invalid attribute type to get the value as a ConstantRange!");
417 return pImpl->getValueAsConstantRange();
422 "Invalid attribute type to get the value as a ConstantRangeList!");
423 return pImpl->getValueAsConstantRangeList();
427 return (pImpl && pImpl->hasAttribute(Kind)) || (!pImpl && Kind ==
None);
432 return pImpl && pImpl->hasAttribute(Kind);
437 "Trying to get alignment from non-alignment attribute!");
443 "Trying to get alignment from non-alignment attribute!");
449 "Trying to get dereferenceable bytes from "
450 "non-dereferenceable attribute!");
451 return pImpl->getValueAsInt();
456 "Trying to get dereferenceable bytes from "
457 "non-dereferenceable attribute!");
458 return pImpl->getValueAsInt();
461std::pair<unsigned, std::optional<unsigned>>
464 "Trying to get allocsize args from non-allocsize attribute");
470 "Trying to get vscale args from non-vscale attribute");
476 "Trying to get vscale args from non-vscale attribute");
482 "Trying to get unwind table kind from non-uwtable attribute");
488 "Trying to get allockind value from non-allockind attribute");
494 "Can only call getMemoryEffects() on memory attribute");
500 "Can only call getCaptureInfo() on captures attribute");
506 "Can only call getNoFPClass() on nofpclass attribute");
507 return static_cast<FPClassTest>(pImpl->getValueAsInt());
512 "Trying to get range args from non-range attribute");
513 return pImpl->getValueAsConstantRange();
518 "Trying to get initializes attr from non-ConstantRangeList attribute");
519 return pImpl->getValueAsConstantRangeList();
537 if (!pImpl)
return {};
562 auto AttrWithBytesToString = [&](
const char *Name) {
569 return AttrWithBytesToString(
"alignstack");
572 return AttrWithBytesToString(
"dereferenceable");
575 return AttrWithBytesToString(
"dereferenceable_or_null");
579 std::optional<unsigned> NumElems;
583 ?
"allocsize(" +
Twine(ElemSize) +
"," +
Twine(*NumElems) +
")"
584 :
"allocsize(" +
Twine(ElemSize) +
")")
591 return (
"vscale_range(" +
Twine(MinValue) +
"," +
592 Twine(MaxValue.value_or(0)) +
")")
617 return (
"allockind(\"" +
652 OS <<
"inaccessiblemem: ";
675 std::string Result =
"nofpclass";
697 OS <<
"initializes(";
718 const auto &AttrVal = pImpl->getValueAsString();
719 if (!AttrVal.empty()) {
732 assert(
isValid() &&
"invalid Attribute doesn't refer to any context");
736 return C.pImpl->AttrsSet.FindNodeOrInsertPos(
ID, Unused) == pImpl;
740 if (!pImpl && !
A.pImpl)
746 return pImpl->cmp(*
A.pImpl,
true);
750 if (!pImpl && !
A.pImpl)
return false;
751 if (!pImpl)
return true;
752 if (!
A.pImpl)
return false;
753 return *pImpl < *
A.pImpl;
757 ID.AddPointer(pImpl);
771#define GET_ATTR_PROP_TABLE
772#include "llvm/IR/Attributes.inc"
775 unsigned Index = Kind - 1;
776 assert(Index < std::size(AttrPropTable) &&
"Invalid attribute kind");
777 return AttrPropTable[Index];
803 "Unknown intersect property");
869 ->getConstantRangeValue();
875 ->getConstantRangeListValue();
897 "Unclear how to compare range list");
914 return cmp(AI,
false) < 0;
933 B.addAttribute(Kind);
940 B.addAttribute(Kind,
Value);
945 const AttributeSet AS)
const {
952 AttrBuilder
B(
C, *
this);
953 B.merge(AttrBuilder(
C, AS));
958 const AttrBuilder &
B)
const {
962 if (!
B.hasAttributes())
965 AttrBuilder Merged(
C, *
this);
967 return get(
C, Merged);
973 AttrBuilder
B(
C, *
this);
974 B.removeAttribute(Kind);
981 AttrBuilder
B(
C, *
this);
982 B.removeAttribute(Kind);
988 AttrBuilder
B(
C, *
this);
990 if (!
B.overlaps(Attrs))
997std::optional<AttributeSet>
1002 AttrBuilder Intersected(
C);
1004 auto ItBegin0 =
begin();
1005 auto ItEnd0 =
end();
1006 auto ItBegin1 =
Other.begin();
1007 auto ItEnd1 =
Other.end();
1009 while (ItBegin0 != ItEnd0 || ItBegin1 != ItEnd1) {
1014 if (ItBegin1 == ItEnd1)
1015 Attr0 = *ItBegin0++;
1016 else if (ItBegin0 == ItEnd0)
1017 Attr0 = *ItBegin1++;
1019 int Cmp = ItBegin0->cmpKind(*ItBegin1);
1021 Attr0 = *ItBegin0++;
1022 Attr1 = *ItBegin1++;
1024 Attr0 = *ItBegin0++;
1026 Attr0 = *ItBegin1++;
1028 assert(Attr0.
isValid() &&
"Iteration should always yield a valid attr");
1030 auto IntersectEq = [&]() {
1035 Intersected.addAttribute(Attr0);
1043 return std::nullopt;
1052 return std::nullopt;
1058 "Iterator picked up two different attributes in the same iteration");
1063 "Invalid attr type of intersectAnd");
1064 Intersected.addAttribute(Kind);
1071 "Invalid attr type of intersectMin");
1073 Intersected.addRawIntAttr(Kind, NewVal);
1079 case Attribute::Alignment:
1082 Intersected.addAlignmentAttr(
1086 case Attribute::Memory:
1090 case Attribute::Captures:
1094 case Attribute::NoFPClass:
1098 case Attribute::Range: {
1103 Intersected.addRangeAttr(NewRange);
1114 return std::nullopt;
1118 if (Kind == Attribute::ByVal &&
1120 Other.getAttribute(Attribute::Alignment))
1121 return std::nullopt;
1124 return get(
C, Intersected);
1128 return SetNode ? SetNode->getNumAttributes() : 0;
1132 return SetNode ? SetNode->hasAttribute(Kind) :
false;
1136 return SetNode ? SetNode->hasAttribute(Kind) :
false;
1140 return SetNode ? SetNode->getAttribute(Kind) :
Attribute();
1144 return SetNode ? SetNode->getAttribute(Kind) :
Attribute();
1148 return SetNode ? SetNode->getAlignment() : std::nullopt;
1152 return SetNode ? SetNode->getStackAlignment() : std::nullopt;
1156 return SetNode ? SetNode->getDereferenceableBytes() : 0;
1160 return SetNode ? SetNode->getDereferenceableOrNullBytes() : 0;
1164 return SetNode ? SetNode->getAttributeType(Attribute::ByRef) :
nullptr;
1168 return SetNode ? SetNode->getAttributeType(Attribute::ByVal) :
nullptr;
1172 return SetNode ? SetNode->getAttributeType(Attribute::StructRet) :
nullptr;
1176 return SetNode ? SetNode->getAttributeType(Attribute::Preallocated) :
nullptr;
1180 return SetNode ? SetNode->getAttributeType(Attribute::InAlloca) :
nullptr;
1184 return SetNode ? SetNode->getAttributeType(Attribute::ElementType) :
nullptr;
1187std::optional<std::pair<unsigned, std::optional<unsigned>>>
1190 return SetNode->getAllocSizeArgs();
1191 return std::nullopt;
1195 return SetNode ? SetNode->getVScaleRangeMin() : 1;
1199 return SetNode ? SetNode->getVScaleRangeMax() : std::nullopt;
1219 return SetNode ? SetNode->getNoFPClass() :
fcNone;
1223 return SetNode ? SetNode->getAsString(InAttrGrp) :
"";
1229 SetNode->Profile(
ID);
1231 return C.pImpl->AttrsSetNodes.FindNodeOrInsertPos(
ID, Unused) == SetNode;
1235 return SetNode ? SetNode->begin() :
nullptr;
1239 return SetNode ? SetNode->end() :
nullptr;
1242#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1255 : NumAttrs(Attrs.
size()) {
1259 for (
const auto &
I : *
this) {
1260 if (
I.isStringAttribute())
1261 StringAttrs.insert({
I.getKindAsString(),
I });
1263 AvailableAttrs.addAttribute(
I.getKindAsEnum());
1271 return getSorted(
C, SortedAttrs);
1276 if (SortedAttrs.
empty())
1284 for (
const auto &Attr : SortedAttrs)
1305 return getSorted(
C,
B.attrs());
1309 return StringAttrs.count(Kind);
1312std::optional<Attribute>
1316 return std::nullopt;
1321 std::lower_bound(
begin(),
end() - StringAttrs.size(), Kind,
1323 return A.getKindAsEnum() < Kind;
1325 assert(
I !=
end() &&
I->hasAttribute(Kind) &&
"Presence check failed?");
1330 if (
auto A = findEnumAttribute(Kind))
1336 return StringAttrs.lookup(Kind);
1340 if (
auto A = findEnumAttribute(Attribute::Alignment))
1341 return A->getAlignment();
1342 return std::nullopt;
1346 if (
auto A = findEnumAttribute(Attribute::StackAlignment))
1347 return A->getStackAlignment();
1348 return std::nullopt;
1352 if (
auto A = findEnumAttribute(Kind))
1353 return A->getValueAsType();
1358 if (
auto A = findEnumAttribute(Attribute::Dereferenceable))
1359 return A->getDereferenceableBytes();
1364 if (
auto A = findEnumAttribute(Attribute::DereferenceableOrNull))
1365 return A->getDereferenceableOrNullBytes();
1369std::optional<std::pair<unsigned, std::optional<unsigned>>>
1371 if (
auto A = findEnumAttribute(Attribute::AllocSize))
1372 return A->getAllocSizeArgs();
1373 return std::nullopt;
1377 if (
auto A = findEnumAttribute(Attribute::VScaleRange))
1378 return A->getVScaleRangeMin();
1383 if (
auto A = findEnumAttribute(Attribute::VScaleRange))
1384 return A->getVScaleRangeMax();
1385 return std::nullopt;
1389 if (
auto A = findEnumAttribute(Attribute::UWTable))
1390 return A->getUWTableKind();
1395 if (
auto A = findEnumAttribute(Attribute::AllocKind))
1396 return A->getAllocKind();
1401 if (
auto A = findEnumAttribute(Attribute::Memory))
1402 return A->getMemoryEffects();
1407 if (
auto A = findEnumAttribute(Attribute::Captures))
1408 return A->getCaptureInfo();
1413 if (
auto A = findEnumAttribute(Attribute::NoFPClass))
1414 return A->getNoFPClass();
1423 Str +=
I->getAsString(InAttrGrp);
1439 : NumAttrSets(Sets.
size()) {
1440 assert(!Sets.
empty() &&
"pointless AttributeListImpl");
1448 if (!
I.isStringAttribute())
1449 AvailableFunctionAttrs.addAttribute(
I.getKindAsEnum());
1451 for (
const auto &Set : Sets)
1452 for (
const auto &
I : Set)
1453 if (!
I.isStringAttribute())
1454 AvailableSomewhereAttrs.addAttribute(
I.getKindAsEnum());
1463 for (
const auto &Set : Sets)
1464 ID.AddPointer(Set.SetNode);
1468 unsigned *Index)
const {
1469 if (!AvailableSomewhereAttrs.hasAttribute(Kind))
1473 for (
unsigned I = 0, E = NumAttrSets;
I != E; ++
I) {
1474 if (
begin()[
I].hasAttribute(Kind)) {
1485#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1497 assert(!AttrSets.
empty() &&
"pointless AttributeListImpl");
1505 pImpl->
AttrsLists.FindNodeOrInsertPos(
ID, InsertPoint);
1515 pImpl->
AttrsLists.InsertNode(PA, InsertPoint);
1519 return AttributeList(PA);
1524 ArrayRef<std::pair<unsigned, Attribute>> Attrs) {
1530 "Misordered Attributes list!");
1532 [](
const std::pair<unsigned, Attribute> &Pair) {
1533 return Pair.second.isValid();
1535 "Pointless attribute!");
1540 for (
ArrayRef<std::pair<unsigned, Attribute>>::iterator
I =
Attrs.begin(),
1542 unsigned Index =
I->first;
1544 while (
I !=
E &&
I->first == Index) {
1552 return get(
C, AttrPairVec);
1557 ArrayRef<std::pair<unsigned, AttributeSet>> Attrs) {
1563 "Misordered Attributes list!");
1565 [](
const std::pair<unsigned, AttributeSet> &Pair) {
1566 return !Pair.second.hasAttributes();
1568 "Pointless attribute!");
1570 unsigned MaxIndex =
Attrs.back().first;
1573 if (MaxIndex == FunctionIndex &&
Attrs.size() > 1)
1577 for (
const auto &Pair : Attrs)
1580 return getImpl(
C, AttrVec);
1589 unsigned NumSets = 0;
1590 for (
size_t I = ArgAttrs.
size();
I != 0; --
I) {
1591 if (ArgAttrs[
I - 1].hasAttributes()) {
1621 return getImpl(
C, AttrSets);
1624AttributeList AttributeList::get(
LLVMContext &
C,
unsigned Index,
1626 if (!
Attrs.hasAttributes())
1631 return getImpl(
C, AttrSets);
1634AttributeList AttributeList::get(
LLVMContext &
C,
unsigned Index,
1635 const AttrBuilder &
B) {
1639AttributeList AttributeList::get(
LLVMContext &
C,
unsigned Index,
1642 for (
const auto K : Kinds)
1644 return get(
C, Attrs);
1647AttributeList AttributeList::get(
LLVMContext &
C,
unsigned Index,
1650 assert(Kinds.
size() == Values.
size() &&
"Mismatched attribute values.");
1653 for (
const auto K : Kinds)
1655 return get(
C, Attrs);
1658AttributeList AttributeList::get(
LLVMContext &
C,
unsigned Index,
1661 for (
const auto &K : Kinds)
1663 return get(
C, Attrs);
1670 if (
Attrs.size() == 1)
1673 unsigned MaxSize = 0;
1674 for (
const auto &
List : Attrs)
1675 MaxSize = std::max(MaxSize,
List.getNumAttrSets());
1682 for (
unsigned I = 0;
I < MaxSize; ++
I) {
1683 AttrBuilder CurBuilder(
C);
1684 for (
const auto &
List : Attrs)
1685 CurBuilder.merge(AttrBuilder(
C,
List.getAttributes(
I - 1)));
1689 return getImpl(
C, NewAttrSets);
1693AttributeList::addAttributeAtIndex(
LLVMContext &
C,
unsigned Index,
1696 if (
Attrs.hasAttribute(Kind))
1704AttributeList AttributeList::addAttributeAtIndex(
LLVMContext &
C,
unsigned Index,
1708 B.addAttribute(Kind,
Value);
1709 return addAttributesAtIndex(
C, Index,
B);
1712AttributeList AttributeList::addAttributeAtIndex(
LLVMContext &
C,
unsigned Index,
1716 return addAttributesAtIndex(
C, Index,
B);
1719AttributeList AttributeList::setAttributesAtIndex(
LLVMContext &
C,
1724 if (Index >= AttrSets.
size())
1725 AttrSets.
resize(Index + 1);
1729 while (!AttrSets.
empty() && !AttrSets.
back().hasAttributes())
1731 if (AttrSets.
empty())
1733 return AttributeList::getImpl(
C, AttrSets);
1736AttributeList AttributeList::addAttributesAtIndex(
LLVMContext &
C,
1738 const AttrBuilder &
B)
const {
1739 if (!
B.hasAttributes())
1750AttributeList AttributeList::addParamAttribute(
LLVMContext &
C,
1757 if (MaxIndex >= AttrSets.
size())
1758 AttrSets.
resize(MaxIndex + 1);
1760 for (
unsigned ArgNo : ArgNos) {
1762 AttrBuilder
B(
C, AttrSets[Index]);
1767 return getImpl(
C, AttrSets);
1771AttributeList::removeAttributeAtIndex(
LLVMContext &
C,
unsigned Index,
1775 if (Attrs == NewAttrs)
1777 return setAttributesAtIndex(
C, Index, NewAttrs);
1780AttributeList AttributeList::removeAttributeAtIndex(
LLVMContext &
C,
1785 if (Attrs == NewAttrs)
1787 return setAttributesAtIndex(
C, Index, NewAttrs);
1790AttributeList AttributeList::removeAttributesAtIndex(
1795 if (Attrs == NewAttrs)
1797 return setAttributesAtIndex(
C, Index, NewAttrs);
1802 unsigned WithoutIndex)
const {
1807 return setAttributesAtIndex(
C, WithoutIndex,
AttributeSet());
1810AttributeList AttributeList::addDereferenceableRetAttr(
LLVMContext &
C,
1811 uint64_t Bytes)
const {
1813 B.addDereferenceableAttr(Bytes);
1814 return addRetAttributes(
C,
B);
1817AttributeList AttributeList::addDereferenceableParamAttr(
LLVMContext &
C,
1819 uint64_t Bytes)
const {
1821 B.addDereferenceableAttr(Bytes);
1822 return addParamAttributes(
C, Index,
B);
1826AttributeList::addDereferenceableOrNullParamAttr(
LLVMContext &
C,
unsigned Index,
1827 uint64_t Bytes)
const {
1829 B.addDereferenceableOrNullAttr(Bytes);
1830 return addParamAttributes(
C, Index,
B);
1833AttributeList AttributeList::addRangeRetAttr(
LLVMContext &
C,
1837 return addRetAttributes(
C,
B);
1840AttributeList AttributeList::addAllocSizeParamAttr(
1842 const std::optional<unsigned> &NumElemsArg)
const {
1844 B.addAllocSizeAttr(ElemSizeArg, NumElemsArg);
1845 return addParamAttributes(
C, Index,
B);
1848std::optional<AttributeList>
1856 index_iterator(std::max(getNumAttrSets(),
Other.getNumAttrSets()));
1857 for (
unsigned Idx : IndexIt) {
1858 auto IntersectedAS =
1862 return std::nullopt;
1863 if (!IntersectedAS->hasAttributes())
1865 IntersectedAttrs.
push_back(std::make_pair(Idx, *IntersectedAS));
1869 return AttributeList::get(
C, IntersectedAttrs);
1876AttributeSet AttributeList::getParamAttrs(
unsigned ArgNo)
const {
1888bool AttributeList::hasAttributeAtIndex(
unsigned Index,
1893bool AttributeList::hasAttributeAtIndex(
unsigned Index,
StringRef Kind)
const {
1897bool AttributeList::hasAttributesAtIndex(
unsigned Index)
const {
1902 return pImpl && pImpl->hasFnAttribute(Kind);
1905bool AttributeList::hasFnAttr(
StringRef Kind)
const {
1906 return hasAttributeAtIndex(AttributeList::FunctionIndex, Kind);
1910 unsigned *Index)
const {
1911 return pImpl && pImpl->hasAttrSomewhere(Attr, Index);
1914Attribute AttributeList::getAttributeAtIndex(
unsigned Index,
1919Attribute AttributeList::getAttributeAtIndex(
unsigned Index,
1924MaybeAlign AttributeList::getRetAlignment()
const {
1928MaybeAlign AttributeList::getParamAlignment(
unsigned ArgNo)
const {
1932MaybeAlign AttributeList::getParamStackAlignment(
unsigned ArgNo)
const {
1933 return getAttributes(ArgNo + FirstArgIndex).getStackAlignment();
1936Type *AttributeList::getParamByValType(
unsigned Index)
const {
1940Type *AttributeList::getParamStructRetType(
unsigned Index)
const {
1941 return getAttributes(Index + FirstArgIndex).getStructRetType();
1944Type *AttributeList::getParamByRefType(
unsigned Index)
const {
1948Type *AttributeList::getParamPreallocatedType(
unsigned Index)
const {
1949 return getAttributes(Index + FirstArgIndex).getPreallocatedType();
1952Type *AttributeList::getParamInAllocaType(
unsigned Index)
const {
1953 return getAttributes(Index + FirstArgIndex).getInAllocaType();
1956Type *AttributeList::getParamElementType(
unsigned Index)
const {
1957 return getAttributes(Index + FirstArgIndex).getElementType();
1960MaybeAlign AttributeList::getFnStackAlignment()
const {
1961 return getFnAttrs().getStackAlignment();
1964MaybeAlign AttributeList::getRetStackAlignment()
const {
1965 return getRetAttrs().getStackAlignment();
1968uint64_t AttributeList::getRetDereferenceableBytes()
const {
1969 return getRetAttrs().getDereferenceableBytes();
1972uint64_t AttributeList::getParamDereferenceableBytes(
unsigned Index)
const {
1973 return getParamAttrs(Index).getDereferenceableBytes();
1976uint64_t AttributeList::getRetDereferenceableOrNullBytes()
const {
1977 return getRetAttrs().getDereferenceableOrNullBytes();
1981AttributeList::getParamDereferenceableOrNullBytes(
unsigned Index)
const {
1982 return getParamAttrs(Index).getDereferenceableOrNullBytes();
1985std::optional<ConstantRange>
1986AttributeList::getParamRange(
unsigned ArgNo)
const {
1987 auto RangeAttr = getParamAttrs(ArgNo).getAttribute(Attribute::Range);
1988 if (RangeAttr.isValid())
1989 return RangeAttr.getRange();
1990 return std::nullopt;
1993FPClassTest AttributeList::getRetNoFPClass()
const {
1994 return getRetAttrs().getNoFPClass();
1997FPClassTest AttributeList::getParamNoFPClass(
unsigned Index)
const {
1998 return getParamAttrs(Index).getNoFPClass();
2001UWTableKind AttributeList::getUWTableKind()
const {
2002 return getFnAttrs().getUWTableKind();
2006 return getFnAttrs().getAllocKind();
2010 return getFnAttrs().getMemoryEffects();
2013std::string AttributeList::getAsString(
unsigned Index,
bool InAttrGrp)
const {
2017AttributeSet AttributeList::getAttributes(
unsigned Index)
const {
2019 if (!pImpl || Index >= getNumAttrSets())
2021 return pImpl->begin()[
Index];
2024bool AttributeList::hasParentContext(
LLVMContext &
C)
const {
2025 assert(!isEmpty() &&
"an empty attribute list has no parent context");
2029 return C.pImpl->AttrsLists.FindNodeOrInsertPos(
ID, Unused) == pImpl;
2032AttributeList::iterator AttributeList::begin()
const {
2033 return pImpl ? pImpl->begin() :
nullptr;
2036AttributeList::iterator AttributeList::end()
const {
2037 return pImpl ? pImpl->end() :
nullptr;
2044unsigned AttributeList::getNumAttrSets()
const {
2045 return pImpl ? pImpl->NumAttrSets : 0;
2049 O <<
"AttributeList[\n";
2051 for (
unsigned i : indexes()) {
2056 case AttrIndex::ReturnIndex:
2059 case AttrIndex::FunctionIndex:
2063 O <<
"arg(" << i - AttrIndex::FirstArgIndex <<
")";
2065 O <<
" => " << getAsString(i) <<
" }\n";
2071#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2084void AttrBuilder::clear() {
Attrs.clear(); }
2114template <
typename K>
2118 if (It != Attrs.end() && It->hasAttribute(Kind))
2121 Attrs.insert(It, Attr);
2124AttrBuilder &AttrBuilder::addAttribute(
Attribute Attr) {
2144 auto It =
lower_bound(Attrs, Val, AttributeComparator());
2145 if (It !=
Attrs.end() && It->hasAttribute(Val))
2150AttrBuilder &AttrBuilder::removeAttribute(
StringRef A) {
2151 auto It =
lower_bound(Attrs,
A, AttributeComparator());
2152 if (It !=
Attrs.end() && It->hasAttribute(
A))
2157std::optional<uint64_t>
2162 return A.getValueAsInt();
2163 return std::nullopt;
2171std::optional<std::pair<unsigned, std::optional<unsigned>>>
2172AttrBuilder::getAllocSizeArgs()
const {
2173 Attribute A = getAttribute(Attribute::AllocSize);
2175 return A.getAllocSizeArgs();
2176 return std::nullopt;
2184 return addRawIntAttr(Attribute::Alignment,
Align->
value());
2192 assert(*
Align <= 0x100 &&
"Alignment too large.");
2193 return addRawIntAttr(Attribute::StackAlignment,
Align->
value());
2196AttrBuilder &AttrBuilder::addDereferenceableAttr(uint64_t Bytes) {
2197 if (Bytes == 0)
return *
this;
2199 return addRawIntAttr(Attribute::Dereferenceable, Bytes);
2202AttrBuilder &AttrBuilder::addDereferenceableOrNullAttr(uint64_t Bytes) {
2206 return addRawIntAttr(Attribute::DereferenceableOrNull, Bytes);
2210AttrBuilder::addAllocSizeAttr(
unsigned ElemSize,
2211 const std::optional<unsigned> &NumElems) {
2215AttrBuilder &AttrBuilder::addAllocSizeAttrFromRawRepr(uint64_t RawArgs) {
2217 assert(RawArgs &&
"Invalid allocsize arguments -- given allocsize(0, 0)");
2218 return addRawIntAttr(Attribute::AllocSize, RawArgs);
2221AttrBuilder &AttrBuilder::addVScaleRangeAttr(
unsigned MinValue,
2222 std::optional<unsigned> MaxValue) {
2226AttrBuilder &AttrBuilder::addVScaleRangeAttrFromRawRepr(uint64_t RawArgs) {
2231 return addRawIntAttr(Attribute::VScaleRange, RawArgs);
2234AttrBuilder &AttrBuilder::addUWTableAttr(
UWTableKind Kind) {
2237 return addRawIntAttr(Attribute::UWTable, uint64_t(Kind));
2241 return addRawIntAttr(Attribute::Memory, ME.
toIntValue());
2244AttrBuilder &AttrBuilder::addCapturesAttr(
CaptureInfo CI) {
2245 return addRawIntAttr(Attribute::Captures, CI.
toIntValue());
2248AttrBuilder &AttrBuilder::addNoFPClassAttr(
FPClassTest Mask) {
2252 return addRawIntAttr(Attribute::NoFPClass, Mask);
2255AttrBuilder &AttrBuilder::addAllocKindAttr(
AllocFnKind Kind) {
2256 return addRawIntAttr(Attribute::AllocKind,
static_cast<uint64_t
>(Kind));
2262 return A.isValid() ?
A.getValueAsType() :
nullptr;
2269AttrBuilder &AttrBuilder::addByValAttr(
Type *Ty) {
2270 return addTypeAttr(Attribute::ByVal, Ty);
2273AttrBuilder &AttrBuilder::addStructRetAttr(
Type *Ty) {
2274 return addTypeAttr(Attribute::StructRet, Ty);
2277AttrBuilder &AttrBuilder::addByRefAttr(
Type *Ty) {
2278 return addTypeAttr(Attribute::ByRef, Ty);
2281AttrBuilder &AttrBuilder::addPreallocatedAttr(
Type *Ty) {
2282 return addTypeAttr(Attribute::Preallocated, Ty);
2285AttrBuilder &AttrBuilder::addInAllocaAttr(
Type *Ty) {
2286 return addTypeAttr(Attribute::InAlloca, Ty);
2297AttrBuilder &AttrBuilder::addRangeAttr(
const ConstantRange &CR) {
2298 return addConstantRangeAttr(Attribute::Range, CR);
2308 return addConstantRangeListAttr(Attribute::Initializes, CRL.
rangesRef());
2311AttrBuilder &AttrBuilder::addFromEquivalentMetadata(
const Instruction &
I) {
2312 if (
I.hasMetadata(LLVMContext::MD_nonnull))
2313 addAttribute(Attribute::NonNull);
2315 if (
I.hasMetadata(LLVMContext::MD_noundef))
2316 addAttribute(Attribute::NoUndef);
2318 if (
const MDNode *
Align =
I.getMetadata(LLVMContext::MD_align)) {
2323 if (
const MDNode *Dereferenceable =
2324 I.getMetadata(LLVMContext::MD_dereferenceable)) {
2330 if (
const MDNode *DereferenceableOrNull =
2331 I.getMetadata(LLVMContext::MD_dereferenceable_or_null)) {
2337 if (
const MDNode *
Range =
I.getMetadata(LLVMContext::MD_range))
2343AttrBuilder &AttrBuilder::merge(
const AttrBuilder &
B) {
2345 for (
const auto &
I :
B.attrs())
2362 auto It =
lower_bound(Attrs,
A, AttributeComparator());
2363 if (It !=
Attrs.end() && It->hasAttribute(
A))
2369 auto It =
lower_bound(Attrs,
A, AttributeComparator());
2370 if (It !=
Attrs.end() && It->hasAttribute(
A))
2375std::optional<ConstantRange> AttrBuilder::getRange()
const {
2376 const Attribute RangeAttr = getAttribute(Attribute::Range);
2379 return std::nullopt;
2383 return getAttribute(
A).isValid();
2386bool AttrBuilder::contains(
StringRef A)
const {
2387 return getAttribute(
A).isValid();
2390bool AttrBuilder::operator==(
const AttrBuilder &
B)
const {
2400bool AttributeFuncs::isNoFPClassCompatibleType(
Type *Ty) {
2406 AttributeSafetyKind ASK) {
2409 if (!Ty->isIntegerTy()) {
2411 if (ASK & ASK_SAFE_TO_DROP)
2413 if (ASK & ASK_UNSAFE_TO_DROP)
2417 if (!Ty->isIntOrIntVectorTy()) {
2419 if (ASK & ASK_SAFE_TO_DROP)
2428 if (!Ty->isPointerTy()) {
2430 if (ASK & ASK_SAFE_TO_DROP)
2442 if (ASK & ASK_UNSAFE_TO_DROP)
2455 if (!Ty->isPtrOrPtrVectorTy()) {
2456 if (ASK & ASK_SAFE_TO_DROP)
2460 if (ASK & ASK_SAFE_TO_DROP) {
2461 if (!isNoFPClassCompatibleType(Ty))
2466 if (Ty->isVoidTy()) {
2467 if (ASK & ASK_SAFE_TO_DROP)
2471 return Incompatible;
2505 DenormalMode CallerModeF32 = Caller.getDenormalModeF32Raw();
2506 DenormalMode CalleeModeF32 = Callee.getDenormalModeF32Raw();
2508 CallerModeF32 = CallerMode;
2510 CalleeModeF32 = CalleeMode;
2520 return !Callee.getAttributes().hasFnAttr(Attribute::StrictFP) ||
2521 Caller.getAttributes().hasFnAttr(Attribute::StrictFP);
2524template<
typename AttrClass>
2526 return Caller.getFnAttribute(AttrClass::getKind()) ==
2527 Callee.getFnAttribute(AttrClass::getKind());
2532 return Caller.getFnAttribute(AttrName) == Callee.getFnAttribute(AttrName);
2540template<
typename AttrClass>
2542 if (AttrClass::isSet(Caller, AttrClass::getKind()) &&
2543 !AttrClass::isSet(Callee, AttrClass::getKind()))
2544 AttrClass::set(Caller, AttrClass::getKind(),
false);
2552template<
typename AttrClass>
2554 if (!AttrClass::isSet(Caller, AttrClass::getKind()) &&
2555 AttrClass::isSet(Callee, AttrClass::getKind()))
2556 AttrClass::set(Caller, AttrClass::getKind(),
true);
2565 if (!Caller.hasStackProtectorFnAttr())
2576 if (Callee.hasFnAttribute(Attribute::StackProtectReq)) {
2577 Caller.removeFnAttrs(OldSSPAttr);
2578 Caller.addFnAttr(Attribute::StackProtectReq);
2579 }
else if (Callee.hasFnAttribute(Attribute::StackProtectStrong) &&
2580 !Caller.hasFnAttribute(Attribute::StackProtectReq)) {
2581 Caller.removeFnAttrs(OldSSPAttr);
2582 Caller.addFnAttr(Attribute::StackProtectStrong);
2583 }
else if (Callee.hasFnAttribute(Attribute::StackProtect) &&
2584 !Caller.hasFnAttribute(Attribute::StackProtectReq) &&
2585 !Caller.hasFnAttribute(Attribute::StackProtectStrong))
2586 Caller.addFnAttr(Attribute::StackProtect);
2592 if (!Caller.hasFnAttribute(
"probe-stack") &&
2593 Callee.hasFnAttribute(
"probe-stack")) {
2594 Caller.addFnAttr(Callee.getFnAttribute(
"probe-stack"));
2603 Attribute CalleeAttr = Callee.getFnAttribute(
"stack-probe-size");
2605 Attribute CallerAttr = Caller.getFnAttribute(
"stack-probe-size");
2607 uint64_t CallerStackProbeSize, CalleeStackProbeSize;
2611 if (CallerStackProbeSize > CalleeStackProbeSize) {
2612 Caller.addFnAttr(CalleeAttr);
2615 Caller.addFnAttr(CalleeAttr);
2631 Attribute CallerAttr = Caller.getFnAttribute(
"min-legal-vector-width");
2633 Attribute CalleeAttr = Callee.getFnAttribute(
"min-legal-vector-width");
2635 uint64_t CallerVectorWidth, CalleeVectorWidth;
2638 if (CallerVectorWidth < CalleeVectorWidth)
2639 Caller.addFnAttr(CalleeAttr);
2643 Caller.removeFnAttr(
"min-legal-vector-width");
2652 if (Callee.nullPointerIsDefined() && !Caller.nullPointerIsDefined()) {
2653 Caller.addFnAttr(Attribute::NullPointerIsValid);
2676 return A.getValueAsString() ==
"true";
2681 Fn.
addFnAttr(Kind, Val ?
"true" :
"false");
2685#define GET_ATTR_NAMES
2686#define ATTRIBUTE_ENUM(ENUM_NAME, DISPLAY_NAME) \
2687 struct ENUM_NAME##Attr : EnumAttr { \
2688 static enum Attribute::AttrKind getKind() { \
2689 return llvm::Attribute::ENUM_NAME; \
2692#define ATTRIBUTE_STRBOOL(ENUM_NAME, DISPLAY_NAME) \
2693 struct ENUM_NAME##Attr : StrBoolAttr { \
2694 static StringRef getKind() { return #DISPLAY_NAME; } \
2696#include "llvm/IR/Attributes.inc"
2698#define GET_ATTR_COMPAT_FUNC
2699#include "llvm/IR/Attributes.inc"
2701bool AttributeFuncs::areInlineCompatible(
const Function &Caller,
2703 return hasCompatibleFnAttrs(Caller, Callee);
2708 return hasCompatibleFnAttrs(
A,
B);
2711void AttributeFuncs::mergeAttributesForInlining(
Function &Caller,
2713 mergeFnAttrs(Caller, Callee);
2726 mergeFnAttrs(
Base, ToMerge);
2729void AttributeFuncs::updateMinLegalVectorWidthAttr(
Function &Fn,
2735 if (Width > OldWidth)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines various helper methods and classes used by LLVMContextImpl for creating and managin...
static void addAttributeImpl(SmallVectorImpl< Attribute > &Attrs, K Kind, Attribute Attr)
static void setAND(Function &Caller, const Function &Callee)
Compute the logical AND of the attributes of the caller and the callee.
static void adjustCallerStackProbes(Function &Caller, const Function &Callee)
If the inlined function required stack probes, then ensure that the calling function has those too.
static std::pair< unsigned, std::optional< unsigned > > unpackVScaleRangeArgs(uint64_t Value)
static void adjustMinLegalVectorWidth(Function &Caller, const Function &Callee)
If the inlined function defines a min legal vector width, then ensure the calling function has the sa...
static void adjustCallerStackProbeSize(Function &Caller, const Function &Callee)
If the inlined function defines the size of guard region on the stack, then ensure that the calling f...
static void adjustCallerSSPLevel(Function &Caller, const Function &Callee)
If the inlined function had a higher stack protection level than the calling function,...
static bool checkStrictFP(const Function &Caller, const Function &Callee)
static uint64_t packAllocSizeArgs(unsigned ElemSizeArg, const std::optional< unsigned > &NumElemsArg)
static uint64_t packVScaleRangeArgs(unsigned MinValue, std::optional< unsigned > MaxValue)
static bool hasIntersectProperty(Attribute::AttrKind Kind, AttributeProperty Prop)
static unsigned attrIdxToArrayIdx(unsigned Index)
Map from AttributeList index to the internal array index.
static bool denormModeCompatible(DenormalMode CallerMode, DenormalMode CalleeMode)
Callees with dynamic denormal modes are compatible with any caller mode.
static void adjustNullPointerValidAttr(Function &Caller, const Function &Callee)
If the inlined function has null_pointer_is_valid attribute, set this attribute in the caller post in...
static const unsigned AllocSizeNumElemsNotPresent
static std::pair< unsigned, std::optional< unsigned > > unpackAllocSizeArgs(uint64_t Num)
static bool checkDenormMode(const Function &Caller, const Function &Callee)
static unsigned getAttributeProperties(Attribute::AttrKind Kind)
static void setOR(Function &Caller, const Function &Callee)
Compute the logical OR of the attributes of the caller and the callee.
static bool hasAttributeProperty(Attribute::AttrKind Kind, AttributeProperty Prop)
static const char * getModRefStr(ModRefInfo MR)
This file contains the simple types necessary to represent the attributes associated with functions a...
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
This file defines a hash set that can be used to remove duplication of nodes in a graph.
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
This file defines the SmallVector class.
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
LLVM_ABI void Profile(FoldingSetNodeID &id) const
Used to insert APInt objects, or objects that contain APInt objects, into FoldingSets.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
const T & back() const
back - Get the last element.
ArrayRef< T > take_front(size_t N=1) const
Return a copy of *this with only the first N elements.
size_t size() const
size - Get the array size.
bool empty() const
empty - Check if the array is empty.
This class represents a single, uniqued attribute.
int cmp(const AttributeImpl &AI, bool KindOnly) const
Used to sort attributes.
bool isConstantRangeAttribute() const
bool hasAttribute(Attribute::AttrKind A) const
Type * getValueAsType() const
Attribute::AttrKind getKindAsEnum() const
bool operator<(const AttributeImpl &AI) const
Used when sorting the attributes.
uint64_t getValueAsInt() const
bool isIntAttribute() const
bool isTypeAttribute() const
AttributeImpl(AttrEntryKind KindID)
bool getValueAsBool() const
StringRef getKindAsString() const
StringRef getValueAsString() const
bool isEnumAttribute() const
ArrayRef< ConstantRange > getValueAsConstantRangeList() const
bool isConstantRangeListAttribute() const
bool isStringAttribute() const
const ConstantRange & getValueAsConstantRange() const
This class represents a set of attributes that apply to the function, return type,...
bool hasAttrSomewhere(Attribute::AttrKind Kind, unsigned *Index=nullptr) const
Return true if the specified attribute is set for at least one parameter or for the return value.
void Profile(FoldingSetNodeID &ID) const
AttributeListImpl(ArrayRef< AttributeSet > Sets)
friend class AttributeList
This class stores enough information to efficiently remove some attributes from an existing AttrBuild...
AttributeMask & addAttribute(Attribute::AttrKind Val)
Add an attribute to the mask.
bool contains(Attribute::AttrKind A) const
Return true if the builder has the specified attribute.
This class represents a group of attributes that apply to one element: function, return type,...
MaybeAlign getStackAlignment() const
uint64_t getDereferenceableOrNullBytes() const
std::optional< unsigned > getVScaleRangeMax() const
bool hasAttribute(Attribute::AttrKind Kind) const
Type * getAttributeType(Attribute::AttrKind Kind) const
AllocFnKind getAllocKind() const
CaptureInfo getCaptureInfo() const
unsigned getVScaleRangeMin() const
MaybeAlign getAlignment() const
MemoryEffects getMemoryEffects() const
UWTableKind getUWTableKind() const
std::optional< std::pair< unsigned, std::optional< unsigned > > > getAllocSizeArgs() const
const Attribute * iterator
uint64_t getDereferenceableBytes() const
std::string getAsString(bool InAttrGrp) const
static AttributeSetNode * get(LLVMContext &C, const AttrBuilder &B)
FPClassTest getNoFPClass() const
Attribute getAttribute(Attribute::AttrKind Kind) const
This class holds the attributes for a particular argument, parameter, function, or return value.
LLVM_ABI AllocFnKind getAllocKind() const
bool hasAttributes() const
Return true if attributes exists in this set.
const Attribute * iterator
LLVM_ABI AttributeSet removeAttribute(LLVMContext &C, Attribute::AttrKind Kind) const
Remove the specified attribute from this set.
LLVM_ABI Type * getInAllocaType() const
LLVM_ABI Type * getByValType() const
LLVM_ABI AttributeSet addAttributes(LLVMContext &C, AttributeSet AS) const
Add attributes to the attribute set.
LLVM_ABI MemoryEffects getMemoryEffects() const
LLVM_ABI bool hasAttribute(Attribute::AttrKind Kind) const
Return true if the attribute exists in this set.
LLVM_ABI std::optional< AttributeSet > intersectWith(LLVMContext &C, AttributeSet Other) const
Try to intersect this AttributeSet with Other.
LLVM_ABI Type * getStructRetType() const
LLVM_ABI std::string getAsString(bool InAttrGrp=false) const
LLVM_ABI unsigned getVScaleRangeMin() const
LLVM_ABI std::optional< std::pair< unsigned, std::optional< unsigned > > > getAllocSizeArgs() const
LLVM_ABI UWTableKind getUWTableKind() const
LLVM_ABI bool hasParentContext(LLVMContext &C) const
Return true if this attribute set belongs to the LLVMContext.
LLVM_ABI iterator begin() const
LLVM_ABI iterator end() const
LLVM_ABI AttributeSet removeAttributes(LLVMContext &C, const AttributeMask &AttrsToRemove) const
Remove the specified attributes from this set.
LLVM_ABI std::optional< unsigned > getVScaleRangeMax() const
LLVM_ABI MaybeAlign getStackAlignment() const
LLVM_ABI Attribute getAttribute(Attribute::AttrKind Kind) const
Return the attribute object.
LLVM_ABI Type * getPreallocatedType() const
LLVM_ABI uint64_t getDereferenceableBytes() const
LLVM_ABI MaybeAlign getAlignment() const
LLVM_ABI FPClassTest getNoFPClass() const
LLVM_ABI Type * getElementType() const
LLVM_ABI Type * getByRefType() const
LLVM_ABI CaptureInfo getCaptureInfo() const
AttributeSet()=default
AttributeSet is a trivially copyable value type.
static LLVM_ABI AttributeSet get(LLVMContext &C, const AttrBuilder &B)
LLVM_ABI uint64_t getDereferenceableOrNullBytes() const
LLVM_ABI unsigned getNumAttributes() const
Return the number of attributes in this set.
LLVM_ABI AttributeSet addAttribute(LLVMContext &C, Attribute::AttrKind Kind) const
Add an argument attribute.
Functions, function parameters, and return types can have attributes to indicate how they should be t...
LLVM_ABI bool isStringAttribute() const
Return true if the attribute is a string (target-dependent) attribute.
static LLVM_ABI Attribute getWithStructRetType(LLVMContext &Context, Type *Ty)
static LLVM_ABI Attribute::AttrKind getAttrKindFromName(StringRef AttrName)
LLVM_ABI bool isEnumAttribute() const
Return true if the attribute is an Attribute::AttrKind type.
static LLVM_ABI Attribute getWithStackAlignment(LLVMContext &Context, Align Alignment)
LLVM_ABI const ConstantRange & getRange() const
Returns the value of the range attribute.
static LLVM_ABI bool intersectWithCustom(AttrKind Kind)
LLVM_ABI bool isIntAttribute() const
Return true if the attribute is an integer attribute.
static LLVM_ABI Attribute getWithByRefType(LLVMContext &Context, Type *Ty)
LLVM_ABI std::optional< unsigned > getVScaleRangeMax() const
Returns the maximum value for the vscale_range attribute or std::nullopt when unknown.
LLVM_ABI uint64_t getValueAsInt() const
Return the attribute's value as an integer.
LLVM_ABI unsigned getVScaleRangeMin() const
Returns the minimum value for the vscale_range attribute.
LLVM_ABI AllocFnKind getAllocKind() const
LLVM_ABI bool isConstantRangeAttribute() const
Return true if the attribute is a ConstantRange attribute.
static LLVM_ABI Attribute getWithAllocKind(LLVMContext &Context, AllocFnKind Kind)
LLVM_ABI StringRef getKindAsString() const
Return the attribute's kind as a string.
static LLVM_ABI Attribute getWithPreallocatedType(LLVMContext &Context, Type *Ty)
static LLVM_ABI bool intersectWithMin(AttrKind Kind)
static LLVM_ABI Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)
Return a uniquified Attribute object.
static LLVM_ABI bool canUseAsRetAttr(AttrKind Kind)
static bool isTypeAttrKind(AttrKind Kind)
LLVM_ABI std::string getAsString(bool InAttrGrp=false) const
The Attribute is converted to a string of equivalent mnemonic.
LLVM_ABI uint64_t getDereferenceableOrNullBytes() const
Returns the number of dereferenceable_or_null bytes from the dereferenceable_or_null attribute.
static LLVM_ABI Attribute getWithDereferenceableBytes(LLVMContext &Context, uint64_t Bytes)
LLVM_ABI std::pair< unsigned, std::optional< unsigned > > getAllocSizeArgs() const
Returns the argument numbers for the allocsize attribute.
static LLVM_ABI Attribute getWithUWTableKind(LLVMContext &Context, UWTableKind Kind)
LLVM_ABI FPClassTest getNoFPClass() const
Return the FPClassTest for nofpclass.
static LLVM_ABI Attribute getWithAllocSizeArgs(LLVMContext &Context, unsigned ElemSizeArg, const std::optional< unsigned > &NumElemsArg)
LLVM_ABI Attribute::AttrKind getKindAsEnum() const
Return the attribute's kind as an enum (Attribute::AttrKind).
LLVM_ABI bool getValueAsBool() const
Return the attribute's value as a boolean.
LLVM_ABI ArrayRef< ConstantRange > getInitializes() const
Returns the value of the initializes attribute.
LLVM_ABI const ConstantRange & getValueAsConstantRange() const
Return the attribute's value as a ConstantRange.
LLVM_ABI uint64_t getDereferenceableBytes() const
Returns the number of dereferenceable bytes from the dereferenceable attribute.
static LLVM_ABI Attribute getWithVScaleRangeArgs(LLVMContext &Context, unsigned MinValue, unsigned MaxValue)
LLVM_ABI MemoryEffects getMemoryEffects() const
Returns memory effects.
LLVM_ABI void Profile(FoldingSetNodeID &ID) const
LLVM_ABI UWTableKind getUWTableKind() const
static LLVM_ABI Attribute getWithDereferenceableOrNullBytes(LLVMContext &Context, uint64_t Bytes)
LLVM_ABI ArrayRef< ConstantRange > getValueAsConstantRangeList() const
Return the attribute's value as a ConstantRange array.
LLVM_ABI StringRef getValueAsString() const
Return the attribute's value as a string.
static LLVM_ABI bool isExistingAttribute(StringRef Name)
Return true if the provided string matches the IR name of an attribute.
bool hasKindAsEnum() const
Returns true if the attribute's kind can be represented as an enum (Enum, Integer,...
static LLVM_ABI StringRef getNameFromAttrKind(Attribute::AttrKind AttrKind)
static LLVM_ABI bool canUseAsFnAttr(AttrKind Kind)
static LLVM_ABI bool intersectWithAnd(AttrKind Kind)
static LLVM_ABI Attribute getWithNoFPClass(LLVMContext &Context, FPClassTest Mask)
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
@ None
No attributes have been set.
@ EndAttrKinds
Sentinel value useful for loops.
static bool isConstantRangeAttrKind(AttrKind Kind)
LLVM_ABI bool hasParentContext(LLVMContext &C) const
Return true if this attribute belongs to the LLVMContext.
LLVM_ABI bool isTypeAttribute() const
Return true if the attribute is a type attribute.
static LLVM_ABI Attribute getWithCaptureInfo(LLVMContext &Context, CaptureInfo CI)
static LLVM_ABI Attribute getWithInAllocaType(LLVMContext &Context, Type *Ty)
static bool isIntAttrKind(AttrKind Kind)
static bool isConstantRangeListAttrKind(AttrKind Kind)
LLVM_ABI bool isConstantRangeListAttribute() const
Return true if the attribute is a ConstantRangeList attribute.
static LLVM_ABI Attribute getWithByValType(LLVMContext &Context, Type *Ty)
LLVM_ABI bool hasAttribute(AttrKind Val) const
Return true if the attribute is present.
static bool isEnumAttrKind(AttrKind Kind)
static LLVM_ABI Attribute getWithMemoryEffects(LLVMContext &Context, MemoryEffects ME)
static LLVM_ABI bool canUseAsParamAttr(AttrKind Kind)
bool isValid() const
Return true if the attribute is any kind of attribute.
LLVM_ABI MaybeAlign getStackAlignment() const
Returns the stack alignment field of an attribute as a byte alignment value.
LLVM_ABI MaybeAlign getAlignment() const
Returns the alignment field of an attribute as a byte alignment value.
LLVM_ABI CaptureInfo getCaptureInfo() const
Returns information from captures attribute.
static LLVM_ABI bool intersectMustPreserve(AttrKind Kind)
LLVM_ABI int cmpKind(Attribute A) const
Used to sort attribute by kind.
LLVM_ABI bool operator<(Attribute A) const
Less-than operator. Useful for sorting the attributes list.
static LLVM_ABI Attribute getWithAlignment(LLVMContext &Context, Align Alignment)
Return a uniquified Attribute object that has the specific alignment set.
LLVM_ABI Type * getValueAsType() const
Return the attribute's value as a Type.
LLVM_ATTRIBUTE_RETURNS_NONNULL void * Allocate(size_t Size, Align Alignment)
Allocate space at the specified alignment.
Represents which components of the pointer may be captured in which location.
static CaptureInfo createFromIntValue(uint32_t Data)
static CaptureInfo all()
Create CaptureInfo that may capture all components of the pointer.
uint32_t toIntValue() const
Convert CaptureInfo into an encoded integer value (used by captures attribute).
This is the shared class of boolean and integer constants.
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
static size_t totalSizeToAlloc(ArrayRef< ConstantRange > Val)
This class represents a list of constant ranges.
ArrayRef< ConstantRange > rangesRef() const
LLVM_ABI void print(raw_ostream &OS) const
Print out the ranges to a stream.
This class represents a range of values.
const APInt & getLower() const
Return the lower value for this range.
LLVM_ABI bool isFullSet() const
Return true if this set contains all of the elements possible for this data-type.
const APInt & getUpper() const
Return the upper value for this range.
LLVM_ABI ConstantRange unionWith(const ConstantRange &CR, PreferredRangeType Type=Smallest) const
Return the range that results from the union of this range with another range.
uint32_t getBitWidth() const
Get the bit width of this ConstantRange.
A set of classes that contain the value of the attribute object.
static bool isSupportedFloatingPointType(Type *Ty)
Returns true if Ty is a supported floating-point type for phi, select, or call FPMathOperators.
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
void addFnAttr(Attribute::AttrKind Kind)
Add function attributes to this function.
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
void removeFnAttr(Attribute::AttrKind Kind)
Remove function attributes from this function.
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
FoldingSet< AttributeSetNode > AttrsSetNodes
FoldingSet< AttributeListImpl > AttrsLists
This is an important class for using LLVM in a threaded context.
ModRefInfo getModRef(Location Loc) const
Get ModRefInfo for the given Location.
static MemoryEffectsBase createFromIntValue(uint32_t Data)
uint32_t toIntValue() const
Convert MemoryEffectsBase into an encoded integer value (used by memory attribute).
static MemoryEffectsBase unknown()
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
reference emplace_back(ArgTypes &&... Args)
void reserve(size_type N)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
static size_t totalSizeToAlloc(StringRef Kind, StringRef Val)
StringRef - Represent a constant reference to a string, i.e.
bool getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
std::string str() const
str - Get the contents as an std::string.
constexpr bool empty() const
empty - Check if the string is empty.
int compare(StringRef RHS) const
compare - Compare two strings; the result is negative, zero, or positive if this string is lexicograp...
A switch()-like statement whose cases are string literals.
static constexpr std::enable_if_t< std::is_same_v< Foo< TrailingTys... >, Foo< Tys... > >, size_t > totalSizeToAlloc(typename trailing_objects_internal::ExtractSecondType< TrailingTys, size_t >::type... Counts)
const T * getTrailingObjects() const
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM_ABI void print(raw_ostream &O, bool IsForDebug=false, bool NoDetails=false) const
Print the current type.
LLVM Value Representation.
static constexpr uint64_t MaximumAlignment
This class implements an extremely fast bulk output stream that can only output to a stream.
A raw_ostream that writes to an std::string.
This class provides various memory handling functions that manipulate MemoryBlock instances.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ C
The default llvm calling convention, compatible with C.
LLVM_ABI AttributeList getAttributes(LLVMContext &C, ID id, FunctionType *FT)
Return the attributes for an intrinsic.
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > extract(Y &&MD)
Extract a Value from Metadata.
LLVM_ABI iterator begin() const
This is an optimization pass for GlobalISel generic memory operations.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
bool isEqual(const GCNRPTracker::LiveRegSet &S1, const GCNRPTracker::LiveRegSet &S2)
Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST=nullptr, unsigned DynamicVGPRBlockSize=0)
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
std::string utostr(uint64_t X, bool isNeg=false)
MemoryEffectsBase< IRMemLocation > MemoryEffects
Summary of how a function affects memory in the program.
LLVM_ABI void printEscapedString(StringRef Name, raw_ostream &Out)
Print each character of the specified string, escaping it if it is not printable or if it is an escap...
LLVM_ABI ConstantRange getConstantRangeFromMetadata(const MDNode &RangeMD)
Parse out a conservative ConstantRange from !range metadata.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
@ None
No unwind table requested.
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
void sort(IteratorTy Start, IteratorTy End)
FPClassTest
Floating-point class tests, supported by 'is_fpclass' intrinsic.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly.
bool is_sorted(R &&Range, Compare C)
Wrapper function around std::is_sorted to check if elements in a range R are sorted with respect to a...
ModRefInfo
Flags indicating whether a memory access modifies or references memory.
@ Ref
The access may reference the value stored in memory.
@ ModRef
The access may reference and may modify the value stored in memory.
@ Mod
The access may modify the value stored in memory.
@ NoModRef
The access neither references nor modifies the value stored in memory.
@ ArgMem
Access to memory via argument pointers.
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
@ InaccessibleMem
Memory that is inaccessible via LLVM IR.
std::string join(IteratorT Begin, IteratorT End, StringRef Separator)
Joins the strings in the range [Begin, End), adding Separator between the elements.
auto lower_bound(R &&Range, T &&Value)
Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...
ArrayRef(const T &OneElt) -> ArrayRef< T >
OutputIt copy(R &&Range, OutputIt Out)
void erase_if(Container &C, UnaryPredicate P)
Provide a container algorithm similar to C++ Library Fundamentals v2's erase_if which is equivalent t...
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Attribute comparator that only compares attribute keys.
bool operator()(Attribute A0, StringRef Kind) const
bool operator()(Attribute A0, Attribute A1) const
bool operator()(Attribute A0, Attribute::AttrKind Kind) const
static void set(Function &Fn, Attribute::AttrKind Kind, bool Val)
static bool isSet(const Function &Fn, Attribute::AttrKind Kind)
static bool isSet(const Function &Fn, StringRef Kind)
static void set(Function &Fn, StringRef Kind, bool Val)
This struct is a compact representation of a valid (non-zero power of two) alignment.
uint64_t value() const
This is a hole in the type system and should not be abused.
Represent subnormal handling kind for floating point instruction inputs and outputs.
DenormalModeKind Input
Denormal treatment kind for floating point instruction inputs in the default floating-point environme...
@ Dynamic
Denormals have unknown treatment.
static constexpr DenormalMode getInvalid()
DenormalModeKind Output
Denormal flushing mode for floating point instruction results in the default floating point environme...
static constexpr DenormalMode getDynamic()
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Align valueOrOne() const
For convenience, returns a valid alignment or 1 if undefined.
Function object to check whether the first component of a container supported by std::get (like std::...