25#include "llvm/Config/llvm-config.h"
58 const std::optional<unsigned> &NumElemsArg) {
60 "Attempting to pack a reserved value");
66static std::pair<unsigned, std::optional<unsigned>>
68 unsigned NumElems = Num & std::numeric_limits<unsigned>::max();
69 unsigned ElemSizeArg = Num >> 32;
71 std::optional<unsigned> NumElemsArg;
73 NumElemsArg = NumElems;
74 return std::make_pair(ElemSizeArg, NumElemsArg);
78 std::optional<unsigned> MaxValue) {
79 return uint64_t(MinValue) << 32 | MaxValue.value_or(0);
82static std::pair<unsigned, std::optional<unsigned>>
84 unsigned MaxValue =
Value & std::numeric_limits<unsigned>::max();
85 unsigned MinValue =
Value >> 32;
87 return std::make_pair(MinValue,
88 MaxValue > 0 ? MaxValue : std::optional<unsigned>());
95 "Not an enum or int attribute");
103 assert(Val == 0 &&
"Value must be zero for enum attributes");
115 pImpl->
AttrsSet.InsertNode(PA, InsertPoint);
126 if (!Val.
empty())
ID.AddString(Val);
138 pImpl->
AttrsSet.InsertNode(PA, InsertPoint);
160 pImpl->
AttrsSet.InsertNode(PA, InsertPoint);
173 assert(
A <= 0x100 &&
"Alignment too large.");
179 assert(Bytes &&
"Bytes must be non-zero.");
185 assert(Bytes &&
"Bytes must be non-zero.");
186 return get(
Context, DereferenceableOrNull, Bytes);
226 const std::optional<unsigned> &NumElemsArg) {
227 assert(!(ElemSizeArg == 0 && NumElemsArg && *NumElemsArg == 0) &&
228 "Invalid allocsize arguments -- given allocsize(0, 0)");
240#define GET_ATTR_NAMES
241#define ATTRIBUTE_ENUM(ENUM_NAME, DISPLAY_NAME) \
242 .Case(#DISPLAY_NAME, Attribute::ENUM_NAME)
243#include "llvm/IR/Attributes.inc"
249#define GET_ATTR_NAMES
250#define ATTRIBUTE_ENUM(ENUM_NAME, DISPLAY_NAME) \
251 case Attribute::ENUM_NAME: \
252 return #DISPLAY_NAME;
253#include "llvm/IR/Attributes.inc"
263#define GET_ATTR_NAMES
264#define ATTRIBUTE_ALL(ENUM_NAME, DISPLAY_NAME) .Case(#DISPLAY_NAME, true)
265#include "llvm/IR/Attributes.inc"
290 if (!pImpl)
return None;
292 "Invalid attribute type to get the kind as an enum!");
297 if (!pImpl)
return 0;
299 "Expected the attribute to be an integer attribute!");
304 if (!pImpl)
return false;
306 "Expected the attribute to be a string attribute!");
311 if (!pImpl)
return {};
313 "Invalid attribute type to get the kind as a string!");
318 if (!pImpl)
return {};
320 "Invalid attribute type to get the value as a string!");
325 if (!pImpl)
return {};
327 "Invalid attribute type to get the value as a type!");
343 "Trying to get alignment from non-alignment attribute!");
349 "Trying to get alignment from non-alignment attribute!");
355 "Trying to get dereferenceable bytes from "
356 "non-dereferenceable attribute!");
362 "Trying to get dereferenceable bytes from "
363 "non-dereferenceable attribute!");
367std::pair<unsigned, std::optional<unsigned>>
370 "Trying to get allocsize args from non-allocsize attribute");
376 "Trying to get vscale args from non-vscale attribute");
382 "Trying to get vscale args from non-vscale attribute");
388 "Trying to get unwind table kind from non-uwtable attribute");
394 "Trying to get allockind value from non-allockind attribute");
400 "Can only call getMemoryEffects() on memory attribute");
406 "Can only call getNoFPClass() on nofpclass attribute");
425 if (!pImpl)
return {};
450 auto AttrWithBytesToString = [&](
const char *
Name) {
457 return AttrWithBytesToString(
"alignstack");
460 return AttrWithBytesToString(
"dereferenceable");
463 return AttrWithBytesToString(
"dereferenceable_or_null");
467 std::optional<unsigned> NumElems;
471 ?
"allocsize(" +
Twine(ElemSize) +
"," +
Twine(*NumElems) +
")"
472 :
"allocsize(" +
Twine(ElemSize) +
")")
479 return (
"vscale_range(" +
Twine(MinValue) +
"," +
480 Twine(MaxValue.value_or(0)) +
")")
510 return (
"allockind(\"" +
545 OS <<
"inaccessiblemem: ";
558 std::string Result =
"nofpclass";
579 if (!AttrVal.empty()) {
581 printEscapedString(AttrVal,
OS);
592 assert(
isValid() &&
"invalid Attribute doesn't refer to any context");
596 return C.pImpl->AttrsSet.FindNodeOrInsertPos(
ID, Unused) == pImpl;
600 if (!pImpl && !
A.pImpl)
return false;
601 if (!pImpl)
return true;
602 if (!
A.pImpl)
return false;
603 return *pImpl < *
A.pImpl;
607 ID.AddPointer(pImpl);
616#define GET_ATTR_PROP_TABLE
617#include "llvm/IR/Attributes.inc"
621 unsigned Index = Kind - 1;
622 assert(
Index < std::size(AttrPropTable) &&
"Invalid attribute kind");
623 return AttrPropTable[
Index] & Prop;
723 B.addAttribute(Kind);
730 B.addAttribute(Kind,
Value);
751 B.removeAttribute(Kind);
759 B.removeAttribute(Kind);
767 if (!
B.overlaps(Attrs))
795 return SetNode ? SetNode->
getAlignment() : std::nullopt;
823 return SetNode ? SetNode->
getAttributeType(Attribute::Preallocated) :
nullptr;
831 return SetNode ? SetNode->
getAttributeType(Attribute::ElementType) :
nullptr;
834std::optional<std::pair<unsigned, std::optional<unsigned>>>
866 return SetNode ? SetNode->
getAsString(InAttrGrp) :
"";
874 return C.pImpl->AttrsSetNodes.FindNodeOrInsertPos(
ID, Unused) == SetNode;
878 return SetNode ? SetNode->
begin() :
nullptr;
882 return SetNode ? SetNode->
end() :
nullptr;
885#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
898 : NumAttrs(Attrs.
size()) {
900 llvm::copy(Attrs, getTrailingObjects<Attribute>());
902 for (
const auto &
I : *
this) {
903 if (
I.isStringAttribute())
904 StringAttrs.insert({
I.getKindAsString(),
I });
906 AvailableAttrs.addAttribute(
I.getKindAsEnum());
914 return getSorted(
C, SortedAttrs);
919 if (SortedAttrs.
empty())
927 for (
const auto &Attr : SortedAttrs)
938 void *Mem = ::operator
new(totalSizeToAlloc<Attribute>(SortedAttrs.size()));
948 return getSorted(
C,
B.attrs());
952 return StringAttrs.count(Kind);
955std::optional<Attribute>
964 std::lower_bound(
begin(),
end() - StringAttrs.size(), Kind,
966 return A.getKindAsEnum() < Kind;
968 assert(
I !=
end() &&
I->hasAttribute(Kind) &&
"Presence check failed?");
973 if (
auto A = findEnumAttribute(Kind))
979 return StringAttrs.lookup(Kind);
983 if (
auto A = findEnumAttribute(Attribute::Alignment))
984 return A->getAlignment();
989 if (
auto A = findEnumAttribute(Attribute::StackAlignment))
990 return A->getStackAlignment();
995 if (
auto A = findEnumAttribute(Kind))
996 return A->getValueAsType();
1001 if (
auto A = findEnumAttribute(Attribute::Dereferenceable))
1002 return A->getDereferenceableBytes();
1007 if (
auto A = findEnumAttribute(Attribute::DereferenceableOrNull))
1008 return A->getDereferenceableOrNullBytes();
1012std::optional<std::pair<unsigned, std::optional<unsigned>>>
1014 if (
auto A = findEnumAttribute(Attribute::AllocSize))
1015 return A->getAllocSizeArgs();
1016 return std::nullopt;
1020 if (
auto A = findEnumAttribute(Attribute::VScaleRange))
1021 return A->getVScaleRangeMin();
1026 if (
auto A = findEnumAttribute(Attribute::VScaleRange))
1027 return A->getVScaleRangeMax();
1028 return std::nullopt;
1032 if (
auto A = findEnumAttribute(Attribute::UWTable))
1033 return A->getUWTableKind();
1038 if (
auto A = findEnumAttribute(Attribute::AllocKind))
1039 return A->getAllocKind();
1044 if (
auto A = findEnumAttribute(Attribute::Memory))
1045 return A->getMemoryEffects();
1050 if (
auto A = findEnumAttribute(Attribute::NoFPClass))
1051 return A->getNoFPClass();
1060 Str +=
I->getAsString(InAttrGrp);
1076 : NumAttrSets(Sets.
size()) {
1077 assert(!Sets.
empty() &&
"pointless AttributeListImpl");
1080 llvm::copy(Sets, getTrailingObjects<AttributeSet>());
1085 if (!
I.isStringAttribute())
1088 for (
const auto &Set : Sets)
1089 for (
const auto &
I : Set)
1090 if (!
I.isStringAttribute())
1100 for (
const auto &Set : Sets)
1101 ID.AddPointer(Set.SetNode);
1105 unsigned *
Index)
const {
1110 for (
unsigned I = 0,
E = NumAttrSets;
I !=
E; ++
I) {
1111 if (
begin()[
I].hasAttribute(Kind)) {
1122#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1134 assert(!AttrSets.
empty() &&
"pointless AttributeListImpl");
1142 pImpl->
AttrsLists.FindNodeOrInsertPos(
ID, InsertPoint);
1149 AttributeListImpl::totalSizeToAlloc<AttributeSet>(AttrSets.
size()),
1152 pImpl->
AttrsLists.InsertNode(PA, InsertPoint);
1161 ArrayRef<std::pair<unsigned, Attribute>> Attrs) {
1167 "Misordered Attributes list!");
1169 [](
const std::pair<unsigned, Attribute> &Pair) {
1170 return Pair.second.isValid();
1172 "Pointless attribute!");
1178 E = Attrs.end();
I !=
E; ) {
1179 unsigned Index =
I->first;
1181 while (
I !=
E &&
I->first ==
Index) {
1189 return get(
C, AttrPairVec);
1194 ArrayRef<std::pair<unsigned, AttributeSet>> Attrs) {
1200 "Misordered Attributes list!");
1202 [](
const std::pair<unsigned, AttributeSet> &Pair) {
1203 return !Pair.second.hasAttributes();
1205 "Pointless attribute!");
1207 unsigned MaxIndex = Attrs.back().first;
1211 MaxIndex = Attrs[Attrs.size() - 2].first;
1214 for (
const auto &Pair : Attrs)
1217 return getImpl(
C, AttrVec);
1226 unsigned NumSets = 0;
1227 for (
size_t I = ArgAttrs.
size();
I != 0; --
I) {
1228 if (ArgAttrs[
I - 1].hasAttributes()) {
1258 return getImpl(
C, AttrSets);
1263 if (!Attrs.hasAttributes())
1267 AttrSets[
Index] = Attrs;
1268 return getImpl(
C, AttrSets);
1279 for (
const auto K : Kinds)
1281 return get(
C, Attrs);
1287 assert(Kinds.
size() == Values.
size() &&
"Mismatched attribute values.");
1290 for (
const auto K : Kinds)
1292 return get(
C, Attrs);
1298 for (
const auto &K : Kinds)
1300 return get(
C, Attrs);
1307 if (Attrs.size() == 1)
1310 unsigned MaxSize = 0;
1311 for (
const auto &
List : Attrs)
1312 MaxSize = std::max(MaxSize,
List.getNumAttrSets());
1319 for (
unsigned I = 0;
I < MaxSize; ++
I) {
1321 for (
const auto &
List : Attrs)
1326 return getImpl(
C, NewAttrSets);
1333 if (Attrs.hasAttribute(Kind))
1345 B.addAttribute(Kind,
Value);
1361 if (Index >= AttrSets.
size())
1362 AttrSets.resize(
Index + 1);
1363 AttrSets[
Index] = Attrs;
1366 while (!AttrSets.
empty() && !AttrSets.
back().hasAttributes())
1367 AttrSets.pop_back();
1368 if (AttrSets.
empty())
1370 return AttributeList::getImpl(
C, AttrSets);
1376 if (!
B.hasAttributes())
1394 if (MaxIndex >= AttrSets.
size())
1395 AttrSets.
resize(MaxIndex + 1);
1397 for (
unsigned ArgNo : ArgNos) {
1404 return getImpl(
C, AttrSets);
1412 if (Attrs == NewAttrs)
1414 return setAttributesAtIndex(
C,
Index, NewAttrs);
1422 if (Attrs == NewAttrs)
1424 return setAttributesAtIndex(
C,
Index, NewAttrs);
1430 AttributeSet NewAttrs = Attrs.removeAttributes(
C, AttrsToRemove);
1432 if (Attrs == NewAttrs)
1434 return setAttributesAtIndex(
C,
Index, NewAttrs);
1439 unsigned WithoutIndex)
const {
1444 return setAttributesAtIndex(
C, WithoutIndex,
AttributeSet());
1450 B.addDereferenceableAttr(Bytes);
1458 B.addDereferenceableAttr(Bytes);
1466 B.addDereferenceableOrNullAttr(Bytes);
1472 const std::optional<unsigned> &NumElemsArg) {
1474 B.addAllocSizeAttr(ElemSizeArg, NumElemsArg);
1508 return pImpl && pImpl->hasFnAttribute(Kind);
1516 unsigned *
Index)
const {
1517 return pImpl && pImpl->hasAttrSomewhere(Attr,
Index);
1619 return pImpl->begin()[
Index];
1623 assert(!
isEmpty() &&
"an empty attribute list has no parent context");
1627 return C.pImpl->AttrsLists.FindNodeOrInsertPos(
ID, Unused) == pImpl;
1631 return pImpl ? pImpl->begin() :
nullptr;
1635 return pImpl ? pImpl->end() :
nullptr;
1643 return pImpl ? pImpl->NumAttrSets : 0;
1647 O <<
"AttributeList[\n";
1649 for (
unsigned i :
indexes()) {
1669#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1712template <
typename K>
1716 if (It != Attrs.end() && It->hasAttribute(Kind))
1719 Attrs.insert(It, Attr);
1743 if (It != Attrs.end() && It->hasAttribute(Val))
1750 if (It != Attrs.end() && It->hasAttribute(
A))
1755std::optional<uint64_t>
1760 return A.getValueAsInt();
1761 return std::nullopt;
1769std::optional<std::pair<unsigned, std::optional<unsigned>>>
1773 return A.getAllocSizeArgs();
1774 return std::nullopt;
1790 assert(*
Align <= 0x100 &&
"Alignment too large.");
1795 if (Bytes == 0)
return *
this;
1804 return addRawIntAttr(Attribute::DereferenceableOrNull, Bytes);
1809 const std::optional<unsigned> &NumElems) {
1815 assert(RawArgs &&
"Invalid allocsize arguments -- given allocsize(0, 0)");
1820 std::optional<unsigned> MaxValue) {
1856 return A.isValid() ?
A.getValueAsType() :
nullptr;
1885 for (
const auto &
I :
B.attrs())
1903 if (It != Attrs.end() && It->hasAttribute(
A))
1910 if (It != Attrs.end() && It->hasAttribute(
A))
1924 return Attrs ==
B.Attrs;
1936 while (
ArrayType *ArrTy = dyn_cast<ArrayType>(Ty))
1937 Ty = ArrTy->getElementType();
1993 return Incompatible;
2027 DenormalMode CallerModeF32 = Caller.getDenormalModeF32Raw();
2035template<
typename AttrClass>
2037 return Caller.getFnAttribute(AttrClass::getKind()) ==
2038 Callee.getFnAttribute(AttrClass::getKind());
2046template<
typename AttrClass>
2048 if (AttrClass::isSet(Caller, AttrClass::getKind()) &&
2049 !AttrClass::isSet(
Callee, AttrClass::getKind()))
2050 AttrClass::set(Caller, AttrClass::getKind(),
false);
2058template<
typename AttrClass>
2060 if (!AttrClass::isSet(Caller, AttrClass::getKind()) &&
2061 AttrClass::isSet(
Callee, AttrClass::getKind()))
2062 AttrClass::set(Caller, AttrClass::getKind(),
true);
2071 if (!Caller.hasStackProtectorFnAttr())
2082 if (
Callee.hasFnAttribute(Attribute::StackProtectReq)) {
2083 Caller.removeFnAttrs(OldSSPAttr);
2084 Caller.addFnAttr(Attribute::StackProtectReq);
2085 }
else if (
Callee.hasFnAttribute(Attribute::StackProtectStrong) &&
2086 !Caller.hasFnAttribute(Attribute::StackProtectReq)) {
2087 Caller.removeFnAttrs(OldSSPAttr);
2088 Caller.addFnAttr(Attribute::StackProtectStrong);
2089 }
else if (
Callee.hasFnAttribute(Attribute::StackProtect) &&
2090 !Caller.hasFnAttribute(Attribute::StackProtectReq) &&
2091 !Caller.hasFnAttribute(Attribute::StackProtectStrong))
2092 Caller.addFnAttr(Attribute::StackProtect);
2098 if (!Caller.hasFnAttribute(
"probe-stack") &&
2099 Callee.hasFnAttribute(
"probe-stack")) {
2100 Caller.addFnAttr(
Callee.getFnAttribute(
"probe-stack"));
2111 Attribute CallerAttr = Caller.getFnAttribute(
"stack-probe-size");
2113 uint64_t CallerStackProbeSize, CalleeStackProbeSize;
2117 if (CallerStackProbeSize > CalleeStackProbeSize) {
2118 Caller.addFnAttr(CalleeAttr);
2121 Caller.addFnAttr(CalleeAttr);
2137 Attribute CallerAttr = Caller.getFnAttribute(
"min-legal-vector-width");
2139 Attribute CalleeAttr =
Callee.getFnAttribute(
"min-legal-vector-width");
2141 uint64_t CallerVectorWidth, CalleeVectorWidth;
2144 if (CallerVectorWidth < CalleeVectorWidth)
2145 Caller.addFnAttr(CalleeAttr);
2149 Caller.removeFnAttr(
"min-legal-vector-width");
2158 if (
Callee.nullPointerIsDefined() && !Caller.nullPointerIsDefined()) {
2159 Caller.addFnAttr(Attribute::NullPointerIsValid);
2182 return A.getValueAsString().equals(
"true");
2187 Fn.
addFnAttr(Kind, Val ?
"true" :
"false");
2191#define GET_ATTR_NAMES
2192#define ATTRIBUTE_ENUM(ENUM_NAME, DISPLAY_NAME) \
2193 struct ENUM_NAME##Attr : EnumAttr { \
2194 static enum Attribute::AttrKind getKind() { \
2195 return llvm::Attribute::ENUM_NAME; \
2198#define ATTRIBUTE_STRBOOL(ENUM_NAME, DISPLAY_NAME) \
2199 struct ENUM_NAME##Attr : StrBoolAttr { \
2200 static StringRef getKind() { return #DISPLAY_NAME; } \
2202#include "llvm/IR/Attributes.inc"
2204#define GET_ATTR_COMPAT_FUNC
2205#include "llvm/IR/Attributes.inc"
2209 return hasCompatibleFnAttrs(Caller,
Callee);
2214 return hasCompatibleFnAttrs(
A,
B);
2219 mergeFnAttrs(Caller,
Callee);
2232 mergeFnAttrs(
Base, ToMerge);
2241 if (Width > OldWidth)
2242 Fn.
addFnAttr(
"min-legal-vector-width", llvm::utostr(Width));
amdgpu Simplify well known AMD library false FunctionCallee Callee
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 uint64_t packAllocSizeArgs(unsigned ElemSizeArg, const std::optional< unsigned > &NumElemsArg)
static uint64_t packVScaleRangeArgs(unsigned MinValue, std::optional< unsigned > MaxValue)
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 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< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-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.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallVector class.
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
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.
Class to represent array types.
AttrBuilder & addStructRetAttr(Type *Ty)
This turns a sret type into the form used internally in Attribute.
AttrBuilder & addAlignmentAttr(MaybeAlign Align)
This turns an alignment into the form used internally in Attribute.
AttrBuilder & addVScaleRangeAttrFromRawRepr(uint64_t RawVScaleRangeRepr)
Add a vscale_range attribute, using the representation returned by Attribute.getIntValue().
std::optional< uint64_t > getRawIntAttr(Attribute::AttrKind Kind) const
Return raw (possibly packed/encoded) value of integer attribute or std::nullopt if not set.
AttrBuilder & addAllocKindAttr(AllocFnKind Kind)
Attribute getAttribute(Attribute::AttrKind Kind) const
Return Attribute with the given Kind.
AttrBuilder & addByRefAttr(Type *Ty)
This turns a byref type into the form used internally in Attribute.
AttrBuilder & addNoFPClassAttr(FPClassTest NoFPClassMask)
bool overlaps(const AttributeMask &AM) const
Return true if the builder has any attribute that's in the specified builder.
AttrBuilder & merge(const AttrBuilder &B)
Add the attributes from the builder.
AttrBuilder & addVScaleRangeAttr(unsigned MinValue, std::optional< unsigned > MaxValue)
This turns two ints into the form used internally in Attribute.
AttrBuilder(LLVMContext &Ctx)
AttrBuilder & addRawIntAttr(Attribute::AttrKind Kind, uint64_t Value)
Add integer attribute with raw value (packed/encoded if necessary).
AttrBuilder & addAttribute(Attribute::AttrKind Val)
Add an attribute to the builder.
AttrBuilder & addByValAttr(Type *Ty)
This turns a byval type into the form used internally in Attribute.
AttrBuilder & addDereferenceableAttr(uint64_t Bytes)
This turns the number of dereferenceable bytes into the form used internally in Attribute.
bool contains(Attribute::AttrKind A) const
Return true if the builder has the specified attribute.
AttrBuilder & addMemoryAttr(MemoryEffects ME)
Add memory effect attribute.
AttrBuilder & addAllocSizeAttrFromRawRepr(uint64_t RawAllocSizeRepr)
Add an allocsize attribute, using the representation returned by Attribute.getIntValue().
AttrBuilder & addPreallocatedAttr(Type *Ty)
This turns a preallocated type into the form used internally in Attribute.
AttrBuilder & addStackAlignmentAttr(MaybeAlign Align)
This turns a stack alignment into the form used internally in Attribute.
AttrBuilder & addInAllocaAttr(Type *Ty)
This turns an inalloca type into the form used internally in Attribute.
AttrBuilder & removeAttribute(Attribute::AttrKind Val)
Remove an attribute from the builder.
bool operator==(const AttrBuilder &B) const
Type * getTypeAttr(Attribute::AttrKind Kind) const
Retrieve type for the given type attribute.
AttrBuilder & remove(const AttributeMask &AM)
Remove the attributes from the builder.
AttrBuilder & addDereferenceableOrNullAttr(uint64_t Bytes)
This turns the number of dereferenceable_or_null bytes into the form used internally in Attribute.
AttrBuilder & addTypeAttr(Attribute::AttrKind Kind, Type *Ty)
Add a type attribute with the given type.
std::optional< std::pair< unsigned, std::optional< unsigned > > > getAllocSizeArgs() const
Retrieve the allocsize args, or std::nullopt if the attribute does not exist.
AttrBuilder & addAllocSizeAttr(unsigned ElemSizeArg, const std::optional< unsigned > &NumElemsArg)
This turns one (or two) ints into the form used internally in Attribute.
AttrBuilder & addUWTableAttr(UWTableKind Kind)
This turns the unwind table kind into the form used internally in Attribute.
void addAttribute(Attribute::AttrKind Kind)
bool hasAttribute(Attribute::AttrKind Kind) const
bool hasAttribute(Attribute::AttrKind A) const
void Profile(FoldingSetNodeID &ID) 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
bool getValueAsBool() const
StringRef getKindAsString() const
StringRef getValueAsString() const
bool isEnumAttribute() const
bool isStringAttribute() const
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
bool hasAttributeAtIndex(unsigned Index, Attribute::AttrKind Kind) const
Return true if the attribute exists at the given index.
Type * getParamStructRetType(unsigned ArgNo) const
Return the sret type for the specified function parameter.
AttributeList addDereferenceableParamAttr(LLVMContext &C, unsigned ArgNo, uint64_t Bytes) const
Add the dereferenceable attribute to the attribute set at the given arg index.
AttributeList removeAttributeAtIndex(LLVMContext &C, unsigned Index, Attribute::AttrKind Kind) const
Remove the specified attribute at the specified index from this attribute list.
bool hasAttributesAtIndex(unsigned Index) const
Return true if attribute exists at the given index.
friend class AttributeListImpl
AttributeSet getFnAttrs() const
The function attributes are returned.
index_iterator indexes() const
Use this to iterate over the valid attribute indexes.
AttributeList removeAttributesAtIndex(LLVMContext &C, unsigned Index, const AttributeMask &AttrsToRemove) const
Remove the specified attributes at the specified index from this attribute list.
friend class AttributeSet
AttributeList addAllocSizeParamAttr(LLVMContext &C, unsigned ArgNo, unsigned ElemSizeArg, const std::optional< unsigned > &NumElemsArg)
Add the allocsize attribute to the attribute set at the given arg index.
MaybeAlign getRetStackAlignment() const
Get the stack alignment of the return value.
AttributeList addRetAttributes(LLVMContext &C, const AttrBuilder &B) const
Add a return value attribute to the list.
void print(raw_ostream &O) const
AttributeList addDereferenceableRetAttr(LLVMContext &C, uint64_t Bytes) const
Add the dereferenceable attribute to the attribute set at the given index.
static AttributeList get(LLVMContext &C, ArrayRef< std::pair< unsigned, Attribute > > Attrs)
Create an AttributeList with the specified parameters in it.
AllocFnKind getAllocKind() const
bool isEmpty() const
Return true if there are no attributes.
AttributeSet getRetAttrs() const
The attributes for the ret value are returned.
bool hasFnAttr(Attribute::AttrKind Kind) const
Return true if the attribute exists for the function.
uint64_t getParamDereferenceableBytes(unsigned Index) const
Get the number of dereferenceable bytes (or zero if unknown) of an arg.
MaybeAlign getParamAlignment(unsigned ArgNo) const
Return the alignment for the specified function parameter.
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.
Type * getParamInAllocaType(unsigned ArgNo) const
Return the inalloca type for the specified function parameter.
unsigned getNumAttrSets() const
FPClassTest getRetNoFPClass() const
Get the disallowed floating-point classes of the return value.
std::string getAsString(unsigned Index, bool InAttrGrp=false) const
Return the attributes at the index as a string.
UWTableKind getUWTableKind() const
Get the unwind table kind requested for the function.
MaybeAlign getRetAlignment() const
Return the alignment of the return value.
Type * getParamElementType(unsigned ArgNo) const
Return the elementtype type for the specified function parameter.
Attribute getAttributeAtIndex(unsigned Index, Attribute::AttrKind Kind) const
Return the attribute object that exists at the given index.
Type * getParamPreallocatedType(unsigned ArgNo) const
Return the preallocated type for the specified function parameter.
bool hasParentContext(LLVMContext &C) const
Return true if this attribute list belongs to the LLVMContext.
const AttributeSet * iterator
MaybeAlign getFnStackAlignment() const
Get the stack alignment of the function.
AttributeList addAttributesAtIndex(LLVMContext &C, unsigned Index, const AttrBuilder &B) const
Add attributes to the attribute set at the given index.
Type * getParamByValType(unsigned ArgNo) const
Return the byval type for the specified function parameter.
MaybeAlign getParamStackAlignment(unsigned ArgNo) const
Return the stack alignment for the specified function parameter.
uint64_t getRetDereferenceableBytes() const
Get the number of dereferenceable bytes (or zero if unknown) of the return value.
uint64_t getParamDereferenceableOrNullBytes(unsigned ArgNo) const
Get the number of dereferenceable_or_null bytes (or zero if unknown) of an arg.
AttributeList addDereferenceableOrNullParamAttr(LLVMContext &C, unsigned ArgNo, uint64_t Bytes) const
Add the dereferenceable_or_null attribute to the attribute set at the given arg index.
AttributeSet getAttributes(unsigned Index) const
The attributes for the specified index are returned.
FPClassTest getParamNoFPClass(unsigned ArgNo) const
Get the disallowed floating-point classes of the argument value.
Type * getParamByRefType(unsigned ArgNo) const
Return the byref type for the specified function parameter.
AttributeList addAttributeAtIndex(LLVMContext &C, unsigned Index, Attribute::AttrKind Kind) const
Add an attribute to the attribute set at the given index.
AttributeSet getParamAttrs(unsigned ArgNo) const
The attributes for the argument or parameter at the given index are returned.
AttributeList addParamAttributes(LLVMContext &C, unsigned ArgNo, const AttrBuilder &B) const
Add an argument attribute to the list.
uint64_t getRetDereferenceableOrNullBytes() const
Get the number of dereferenceable_or_null bytes (or zero if unknown) of the return value.
AttributeList addParamAttribute(LLVMContext &C, unsigned ArgNo, Attribute::AttrKind Kind) const
Add an argument attribute to the list.
MemoryEffects getMemoryEffects() const
Returns memory effects of the function.
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.
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
unsigned getVScaleRangeMin() const
MaybeAlign getAlignment() const
MemoryEffects getMemoryEffects() const
UWTableKind getUWTableKind() const
std::optional< std::pair< unsigned, std::optional< unsigned > > > getAllocSizeArgs() const
uint64_t getDereferenceableBytes() const
unsigned getNumAttributes() const
Return the number of attributes this AttributeList contains.
void Profile(FoldingSetNodeID &ID) const
std::string getAsString(bool InAttrGrp) const
static AttributeSetNode * get(LLVMContext &C, const AttrBuilder &B)
FPClassTest getNoFPClass() const
Attribute getAttribute(Attribute::AttrKind Kind) const
AllocFnKind getAllocKind() const
bool hasAttributes() const
Return true if attributes exists in this set.
AttributeSet removeAttribute(LLVMContext &C, Attribute::AttrKind Kind) const
Remove the specified attribute from this set.
Type * getInAllocaType() const
Type * getByValType() const
AttributeSet addAttributes(LLVMContext &C, AttributeSet AS) const
Add attributes to the attribute set.
MemoryEffects getMemoryEffects() const
bool hasAttribute(Attribute::AttrKind Kind) const
Return true if the attribute exists in this set.
Type * getStructRetType() const
std::string getAsString(bool InAttrGrp=false) const
unsigned getVScaleRangeMin() const
std::optional< std::pair< unsigned, std::optional< unsigned > > > getAllocSizeArgs() const
UWTableKind getUWTableKind() const
bool hasParentContext(LLVMContext &C) const
Return true if this attribute set belongs to the LLVMContext.
AttributeSet removeAttributes(LLVMContext &C, const AttributeMask &AttrsToRemove) const
Remove the specified attributes from this set.
std::optional< unsigned > getVScaleRangeMax() const
MaybeAlign getStackAlignment() const
Attribute getAttribute(Attribute::AttrKind Kind) const
Return the attribute object.
Type * getPreallocatedType() const
uint64_t getDereferenceableBytes() const
MaybeAlign getAlignment() const
FPClassTest getNoFPClass() const
Type * getElementType() const
Type * getByRefType() const
AttributeSet()=default
AttributeSet is a trivially copyable value type.
static AttributeSet get(LLVMContext &C, const AttrBuilder &B)
uint64_t getDereferenceableOrNullBytes() const
unsigned getNumAttributes() const
Return the number of attributes in this set.
AttributeSet addAttribute(LLVMContext &C, Attribute::AttrKind Kind) const
Add an argument attribute.
bool isStringAttribute() const
Return true if the attribute is a string (target-dependent) attribute.
static Attribute getWithStructRetType(LLVMContext &Context, Type *Ty)
static Attribute::AttrKind getAttrKindFromName(StringRef AttrName)
bool isEnumAttribute() const
Return true if the attribute is an Attribute::AttrKind type.
static Attribute getWithStackAlignment(LLVMContext &Context, Align Alignment)
bool isIntAttribute() const
Return true if the attribute is an integer attribute.
static Attribute getWithByRefType(LLVMContext &Context, Type *Ty)
std::optional< unsigned > getVScaleRangeMax() const
Returns the maximum value for the vscale_range attribute or std::nullopt when unknown.
uint64_t getValueAsInt() const
Return the attribute's value as an integer.
unsigned getVScaleRangeMin() const
Returns the minimum value for the vscale_range attribute.
AllocFnKind getAllocKind() const
StringRef getKindAsString() const
Return the attribute's kind as a string.
static Attribute getWithPreallocatedType(LLVMContext &Context, Type *Ty)
static Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)
Return a uniquified Attribute object.
static bool canUseAsRetAttr(AttrKind Kind)
static bool isTypeAttrKind(AttrKind Kind)
std::string getAsString(bool InAttrGrp=false) const
The Attribute is converted to a string of equivalent mnemonic.
uint64_t getDereferenceableOrNullBytes() const
Returns the number of dereferenceable_or_null bytes from the dereferenceable_or_null attribute.
static Attribute getWithDereferenceableBytes(LLVMContext &Context, uint64_t Bytes)
std::pair< unsigned, std::optional< unsigned > > getAllocSizeArgs() const
Returns the argument numbers for the allocsize attribute.
static Attribute getWithUWTableKind(LLVMContext &Context, UWTableKind Kind)
FPClassTest getNoFPClass() const
Return the FPClassTest for nofpclass.
static Attribute getWithAllocSizeArgs(LLVMContext &Context, unsigned ElemSizeArg, const std::optional< unsigned > &NumElemsArg)
Attribute::AttrKind getKindAsEnum() const
Return the attribute's kind as an enum (Attribute::AttrKind).
bool getValueAsBool() const
Return the attribute's value as a boolean.
uint64_t getDereferenceableBytes() const
Returns the number of dereferenceable bytes from the dereferenceable attribute.
static Attribute getWithVScaleRangeArgs(LLVMContext &Context, unsigned MinValue, unsigned MaxValue)
MemoryEffects getMemoryEffects() const
Returns memory effects.
void Profile(FoldingSetNodeID &ID) const
UWTableKind getUWTableKind() const
static Attribute getWithDereferenceableOrNullBytes(LLVMContext &Context, uint64_t Bytes)
StringRef getValueAsString() const
Return the attribute's value as a string.
static bool isExistingAttribute(StringRef Name)
Return true if the provided string matches the IR name of an attribute.
static StringRef getNameFromAttrKind(Attribute::AttrKind AttrKind)
static bool canUseAsFnAttr(AttrKind Kind)
static 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
Sentinal value useful for loops.
bool hasParentContext(LLVMContext &C) const
Return true if this attribute belongs to the LLVMContext.
bool isTypeAttribute() const
Return true if the attribute is a type attribute.
static Attribute getWithInAllocaType(LLVMContext &Context, Type *Ty)
static bool isIntAttrKind(AttrKind Kind)
static Attribute getWithByValType(LLVMContext &Context, Type *Ty)
bool hasAttribute(AttrKind Val) const
Return true if the attribute is present.
static bool isEnumAttrKind(AttrKind Kind)
static Attribute getWithMemoryEffects(LLVMContext &Context, MemoryEffects ME)
static bool canUseAsParamAttr(AttrKind Kind)
bool isValid() const
Return true if the attribute is any kind of attribute.
MaybeAlign getStackAlignment() const
Returns the stack alignment field of an attribute as a byte alignment value.
MaybeAlign getAlignment() const
Returns the alignment field of an attribute as a byte alignment value.
bool operator<(Attribute A) const
Less-than operator. Useful for sorting the attributes list.
static Attribute getWithAlignment(LLVMContext &Context, Align Alignment)
Return a uniquified Attribute object that has the specific alignment set.
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.
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< AttributeImpl > AttrsSet
FoldingSet< AttributeSetNode > AttrsSetNodes
FoldingSet< AttributeListImpl > AttrsLists
This is an important class for using LLVM in a threaded context.
LLVMContextImpl *const pImpl
Summary of how a function affects memory in the program.
static MemoryEffects createFromIntValue(uint32_t Data)
Create MemoryEffects from an encoded integer value (used by memory attribute).
@ ArgMem
Access to memory via argument pointers.
@ InaccessibleMem
Memory that is inaccessible via LLVM IR.
ModRefInfo getModRef(Location Loc) const
Get ModRefInfo for the given Location.
uint32_t toIntValue() const
Convert MemoryEffects into an encoded integer value (used by memory attribute).
static auto locations()
Returns iterator over all supported location kinds.
static MemoryEffects unknown()
Create MemoryEffects that can read and write any memory.
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.
A switch()-like statement whose cases are string literals.
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.
bool isPointerTy() const
True if this is an instance of PointerType.
void print(raw_ostream &O, bool IsForDebug=false, bool NoDetails=false) const
Print the current type.
bool isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
bool isIntegerTy() const
True if this is an instance of IntegerType.
bool isFPOrFPVectorTy() const
Return true if this is a FP type or a vector of FP.
bool isVoidTy() const
Return true if this is 'void'.
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.
bool areInlineCompatible(const Function &Caller, const Function &Callee)
AttributeMask getUBImplyingAttributes()
Get param/return attributes which imply immediate undefined behavior if an invalid value is passed.
bool isNoFPClassCompatibleType(Type *Ty)
Returns true if this is a type legal for the 'nofpclass' attribute.
bool areOutlineCompatible(const Function &A, const Function &B)
Checks if there are any incompatible function attributes between A and B.
void updateMinLegalVectorWidthAttr(Function &Fn, uint64_t Width)
Update min-legal-vector-width if it is in Attribute and less than Width.
void mergeAttributesForOutlining(Function &Base, const Function &ToMerge)
Merges the functions attributes from ToMerge into function Base.
void mergeAttributesForInlining(Function &Caller, const Function &Callee)
Merge caller's and callee's attributes.
AttributeMask typeIncompatible(Type *Ty, AttributeSafetyKind ASK=ASK_ALL)
Which attributes cannot be applied to a type.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ C
The default llvm calling convention, compatible with C.
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)
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 a range to a container.
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.
@ Sync
"Synchronous" unwind tables
void sort(IteratorTy Start, IteratorTy End)
FPClassTest
Floating-point class tests, supported by 'is_fpclass' intrinsic.
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.
auto lower_bound(R &&Range, T &&Value)
Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...
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.
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.
Function object to check whether the first component of a container supported by std::get (like std::...