diff options
author | Krzysztof Parzyszek <kparzysz@quicinc.com> | 2022-12-01 21:50:39 -0600 |
---|---|---|
committer | Krzysztof Parzyszek <kparzysz@quicinc.com> | 2022-12-02 08:15:45 -0600 |
commit | 26424c96c03ee4098d7f129de9234a6f177e49ac (patch) | |
tree | ea1667be4c04e72f138317556dc4b7ba9f7f5ff1 /llvm/lib/IR/Attributes.cpp | |
parent | 71f3cac7895ad516ec25438f803ed3c9916c215a (diff) | |
download | llvm-26424c96c03ee4098d7f129de9234a6f177e49ac.zip llvm-26424c96c03ee4098d7f129de9234a6f177e49ac.tar.gz llvm-26424c96c03ee4098d7f129de9234a6f177e49ac.tar.bz2 |
Attributes: convert Optional to std::optional
Diffstat (limited to 'llvm/lib/IR/Attributes.cpp')
-rw-r--r-- | llvm/lib/IR/Attributes.cpp | 68 |
1 files changed, 35 insertions, 33 deletions
diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp index 1a90b94..e4dee3f 100644 --- a/llvm/lib/IR/Attributes.cpp +++ b/llvm/lib/IR/Attributes.cpp @@ -17,7 +17,6 @@ #include "LLVMContextImpl.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/FoldingSet.h" -#include "llvm/ADT/Optional.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringExtras.h" @@ -36,6 +35,7 @@ #include <cstddef> #include <cstdint> #include <limits> +#include <optional> #include <string> #include <tuple> #include <utility> @@ -55,7 +55,7 @@ using namespace llvm; static const unsigned AllocSizeNumElemsNotPresent = -1; static uint64_t packAllocSizeArgs(unsigned ElemSizeArg, - const Optional<unsigned> &NumElemsArg) { + const std::optional<unsigned> &NumElemsArg) { assert((!NumElemsArg || *NumElemsArg != AllocSizeNumElemsNotPresent) && "Attempting to pack a reserved value"); @@ -63,29 +63,29 @@ static uint64_t packAllocSizeArgs(unsigned ElemSizeArg, NumElemsArg.value_or(AllocSizeNumElemsNotPresent); } -static std::pair<unsigned, Optional<unsigned>> +static std::pair<unsigned, std::optional<unsigned>> unpackAllocSizeArgs(uint64_t Num) { unsigned NumElems = Num & std::numeric_limits<unsigned>::max(); unsigned ElemSizeArg = Num >> 32; - Optional<unsigned> NumElemsArg; + std::optional<unsigned> NumElemsArg; if (NumElems != AllocSizeNumElemsNotPresent) NumElemsArg = NumElems; return std::make_pair(ElemSizeArg, NumElemsArg); } static uint64_t packVScaleRangeArgs(unsigned MinValue, - Optional<unsigned> MaxValue) { + std::optional<unsigned> MaxValue) { return uint64_t(MinValue) << 32 | MaxValue.value_or(0); } -static std::pair<unsigned, Optional<unsigned>> +static std::pair<unsigned, std::optional<unsigned>> unpackVScaleRangeArgs(uint64_t Value) { unsigned MaxValue = Value & std::numeric_limits<unsigned>::max(); unsigned MinValue = Value >> 32; return std::make_pair(MinValue, - MaxValue > 0 ? MaxValue : Optional<unsigned>()); + MaxValue > 0 ? MaxValue : std::optional<unsigned>()); } Attribute Attribute::get(LLVMContext &Context, Attribute::AttrKind Kind, @@ -218,7 +218,7 @@ Attribute Attribute::getWithMemoryEffects(LLVMContext &Context, Attribute Attribute::getWithAllocSizeArgs(LLVMContext &Context, unsigned ElemSizeArg, - const Optional<unsigned> &NumElemsArg) { + const std::optional<unsigned> &NumElemsArg) { assert(!(ElemSizeArg == 0 && NumElemsArg && *NumElemsArg == 0) && "Invalid allocsize arguments -- given allocsize(0, 0)"); return get(Context, AllocSize, packAllocSizeArgs(ElemSizeArg, NumElemsArg)); @@ -359,7 +359,8 @@ uint64_t Attribute::getDereferenceableOrNullBytes() const { return pImpl->getValueAsInt(); } -std::pair<unsigned, Optional<unsigned>> Attribute::getAllocSizeArgs() const { +std::pair<unsigned, std::optional<unsigned>> +Attribute::getAllocSizeArgs() const { assert(hasAttribute(Attribute::AllocSize) && "Trying to get allocsize args from non-allocsize attribute"); return unpackAllocSizeArgs(pImpl->getValueAsInt()); @@ -371,7 +372,7 @@ unsigned Attribute::getVScaleRangeMin() const { return unpackVScaleRangeArgs(pImpl->getValueAsInt()).first; } -Optional<unsigned> Attribute::getVScaleRangeMax() const { +std::optional<unsigned> Attribute::getVScaleRangeMax() const { assert(hasAttribute(Attribute::VScaleRange) && "Trying to get vscale args from non-vscale attribute"); return unpackVScaleRangeArgs(pImpl->getValueAsInt()).second; @@ -452,7 +453,7 @@ std::string Attribute::getAsString(bool InAttrGrp) const { if (hasAttribute(Attribute::AllocSize)) { unsigned ElemSize; - Optional<unsigned> NumElems; + std::optional<unsigned> NumElems; std::tie(ElemSize, NumElems) = getAllocSizeArgs(); return (NumElems @@ -463,7 +464,7 @@ std::string Attribute::getAsString(bool InAttrGrp) const { if (hasAttribute(Attribute::VScaleRange)) { unsigned MinValue = getVScaleRangeMin(); - Optional<unsigned> MaxValue = getVScaleRangeMax(); + std::optional<unsigned> MaxValue = getVScaleRangeMax(); return ("vscale_range(" + Twine(MinValue) + "," + Twine(MaxValue.value_or(0)) + ")") .str(); @@ -812,19 +813,19 @@ Type *AttributeSet::getElementType() const { return SetNode ? SetNode->getAttributeType(Attribute::ElementType) : nullptr; } -Optional<std::pair<unsigned, Optional<unsigned>>> +std::optional<std::pair<unsigned, std::optional<unsigned>>> AttributeSet::getAllocSizeArgs() const { if (SetNode) return SetNode->getAllocSizeArgs(); - return None; + return std::nullopt; } unsigned AttributeSet::getVScaleRangeMin() const { return SetNode ? SetNode->getVScaleRangeMin() : 1; } -Optional<unsigned> AttributeSet::getVScaleRangeMax() const { - return SetNode ? SetNode->getVScaleRangeMax() : None; +std::optional<unsigned> AttributeSet::getVScaleRangeMax() const { + return SetNode ? SetNode->getVScaleRangeMax() : std::nullopt; } UWTableKind AttributeSet::getUWTableKind() const { @@ -929,11 +930,11 @@ bool AttributeSetNode::hasAttribute(StringRef Kind) const { return StringAttrs.count(Kind); } -Optional<Attribute> +std::optional<Attribute> AttributeSetNode::findEnumAttribute(Attribute::AttrKind Kind) const { // Do a quick presence check. if (!hasAttribute(Kind)) - return None; + return std::nullopt; // Attributes in a set are sorted by enum value, followed by string // attributes. Binary search the one we want. @@ -986,11 +987,11 @@ uint64_t AttributeSetNode::getDereferenceableOrNullBytes() const { return 0; } -Optional<std::pair<unsigned, Optional<unsigned>>> +std::optional<std::pair<unsigned, std::optional<unsigned>>> AttributeSetNode::getAllocSizeArgs() const { if (auto A = findEnumAttribute(Attribute::AllocSize)) return A->getAllocSizeArgs(); - return None; + return std::nullopt; } unsigned AttributeSetNode::getVScaleRangeMin() const { @@ -999,10 +1000,10 @@ unsigned AttributeSetNode::getVScaleRangeMin() const { return 1; } -Optional<unsigned> AttributeSetNode::getVScaleRangeMax() const { +std::optional<unsigned> AttributeSetNode::getVScaleRangeMax() const { if (auto A = findEnumAttribute(Attribute::VScaleRange)) return A->getVScaleRangeMax(); - return None; + return std::nullopt; } UWTableKind AttributeSetNode::getUWTableKind() const { @@ -1445,10 +1446,9 @@ AttributeList::addDereferenceableOrNullParamAttr(LLVMContext &C, unsigned Index, return addParamAttributes(C, Index, B); } -AttributeList -AttributeList::addAllocSizeParamAttr(LLVMContext &C, unsigned Index, - unsigned ElemSizeArg, - const Optional<unsigned> &NumElemsArg) { +AttributeList AttributeList::addAllocSizeParamAttr( + LLVMContext &C, unsigned Index, unsigned ElemSizeArg, + const std::optional<unsigned> &NumElemsArg) { AttrBuilder B(C); B.addAllocSizeAttr(ElemSizeArg, NumElemsArg); return addParamAttributes(C, Index, B); @@ -1723,12 +1723,13 @@ AttrBuilder &AttrBuilder::removeAttribute(StringRef A) { return *this; } -Optional<uint64_t> AttrBuilder::getRawIntAttr(Attribute::AttrKind Kind) const { +std::optional<uint64_t> +AttrBuilder::getRawIntAttr(Attribute::AttrKind Kind) const { assert(Attribute::isIntAttrKind(Kind) && "Not an int attribute"); Attribute A = getAttribute(Kind); if (A.isValid()) return A.getValueAsInt(); - return None; + return std::nullopt; } AttrBuilder &AttrBuilder::addRawIntAttr(Attribute::AttrKind Kind, @@ -1736,12 +1737,12 @@ AttrBuilder &AttrBuilder::addRawIntAttr(Attribute::AttrKind Kind, return addAttribute(Attribute::get(Ctx, Kind, Value)); } -Optional<std::pair<unsigned, Optional<unsigned>>> +std::optional<std::pair<unsigned, std::optional<unsigned>>> AttrBuilder::getAllocSizeArgs() const { Attribute A = getAttribute(Attribute::AllocSize); if (A.isValid()) return A.getAllocSizeArgs(); - return None; + return std::nullopt; } AttrBuilder &AttrBuilder::addAlignmentAttr(MaybeAlign Align) { @@ -1774,8 +1775,9 @@ AttrBuilder &AttrBuilder::addDereferenceableOrNullAttr(uint64_t Bytes) { return addRawIntAttr(Attribute::DereferenceableOrNull, Bytes); } -AttrBuilder &AttrBuilder::addAllocSizeAttr(unsigned ElemSize, - const Optional<unsigned> &NumElems) { +AttrBuilder & +AttrBuilder::addAllocSizeAttr(unsigned ElemSize, + const std::optional<unsigned> &NumElems) { return addAllocSizeAttrFromRawRepr(packAllocSizeArgs(ElemSize, NumElems)); } @@ -1786,7 +1788,7 @@ AttrBuilder &AttrBuilder::addAllocSizeAttrFromRawRepr(uint64_t RawArgs) { } AttrBuilder &AttrBuilder::addVScaleRangeAttr(unsigned MinValue, - Optional<unsigned> MaxValue) { + std::optional<unsigned> MaxValue) { return addVScaleRangeAttrFromRawRepr(packVScaleRangeArgs(MinValue, MaxValue)); } |