Author: Krzysztof Parzyszek Date: 2022-12-02T08:15:45-06:00 New Revision: 26424c96c03ee4098d7f129de9234a6f177e49ac
URL: https://github.com/llvm/llvm-project/commit/26424c96c03ee4098d7f129de9234a6f177e49ac DIFF: https://github.com/llvm/llvm-project/commit/26424c96c03ee4098d7f129de9234a6f177e49ac.diff LOG: Attributes: convert Optional to std::optional Added: Modified: clang/lib/CodeGen/CGCall.cpp llvm/include/llvm/Analysis/TargetTransformInfo.h llvm/include/llvm/Analysis/TargetTransformInfoImpl.h llvm/include/llvm/AsmParser/LLParser.h llvm/include/llvm/CodeGen/BasicTTIImpl.h llvm/include/llvm/IR/Attributes.h llvm/lib/Analysis/InstructionSimplify.cpp llvm/lib/Analysis/MemoryBuiltins.cpp llvm/lib/Analysis/TargetTransformInfo.cpp llvm/lib/Analysis/ValueTracking.cpp llvm/lib/AsmParser/LLParser.cpp llvm/lib/IR/AttributeImpl.h llvm/lib/IR/Attributes.cpp llvm/lib/IR/Verifier.cpp llvm/lib/Target/AArch64/AArch64TargetMachine.cpp llvm/lib/Target/AArch64/AArch64TargetTransformInfo.h llvm/lib/Target/AArch64/SVEIntrinsicOpts.cpp llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp llvm/lib/Transforms/Utils/BuildLibCalls.cpp llvm/lib/Transforms/Vectorize/LoopVectorize.cpp Removed: ################################################################################ diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index 0f410a8daae66..df500a5981f4c 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -40,6 +40,7 @@ #include "llvm/IR/Intrinsics.h" #include "llvm/IR/Type.h" #include "llvm/Transforms/Utils/Local.h" +#include <optional> using namespace clang; using namespace CodeGen; @@ -2205,7 +2206,7 @@ void CodeGenModule::ConstructAttributeList(StringRef Name, HasOptnone = TargetDecl->hasAttr<OptimizeNoneAttr>(); if (auto *AllocSize = TargetDecl->getAttr<AllocSizeAttr>()) { - Optional<unsigned> NumElemsParam; + std::optional<unsigned> NumElemsParam; if (AllocSize->getNumElemsParam().isValid()) NumElemsParam = AllocSize->getNumElemsParam().getLLVMIndex(); FuncAttrs.addAllocSizeAttr(AllocSize->getElemSizeParam().getLLVMIndex(), diff --git a/llvm/include/llvm/Analysis/TargetTransformInfo.h b/llvm/include/llvm/Analysis/TargetTransformInfo.h index 592f1146b5cd5..f26fe677a8d1a 100644 --- a/llvm/include/llvm/Analysis/TargetTransformInfo.h +++ b/llvm/include/llvm/Analysis/TargetTransformInfo.h @@ -972,10 +972,10 @@ class TargetTransformInfo { /// \return The maximum value of vscale if the target specifies an /// architectural maximum vector length, and None otherwise. - Optional<unsigned> getMaxVScale() const; + std::optional<unsigned> getMaxVScale() const; /// \return the value of vscale to tune the cost model for. - Optional<unsigned> getVScaleForTuning() const; + std::optional<unsigned> getVScaleForTuning() const; /// \return True if the vectorization factor should be chosen to /// make the vector of the smallest element type match the size of a @@ -1715,8 +1715,8 @@ class TargetTransformInfo::Concept { virtual const char *getRegisterClassName(unsigned ClassID) const = 0; virtual TypeSize getRegisterBitWidth(RegisterKind K) const = 0; virtual unsigned getMinVectorRegisterBitWidth() const = 0; - virtual Optional<unsigned> getMaxVScale() const = 0; - virtual Optional<unsigned> getVScaleForTuning() const = 0; + virtual std::optional<unsigned> getMaxVScale() const = 0; + virtual std::optional<unsigned> getVScaleForTuning() const = 0; virtual bool shouldMaximizeVectorBandwidth(TargetTransformInfo::RegisterKind K) const = 0; virtual ElementCount getMinimumVF(unsigned ElemWidth, @@ -2239,10 +2239,10 @@ class TargetTransformInfo::Model final : public TargetTransformInfo::Concept { unsigned getMinVectorRegisterBitWidth() const override { return Impl.getMinVectorRegisterBitWidth(); } - Optional<unsigned> getMaxVScale() const override { + std::optional<unsigned> getMaxVScale() const override { return Impl.getMaxVScale(); } - Optional<unsigned> getVScaleForTuning() const override { + std::optional<unsigned> getVScaleForTuning() const override { return Impl.getVScaleForTuning(); } bool shouldMaximizeVectorBandwidth( diff --git a/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h b/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h index 05cab5b45e282..b21a001810938 100644 --- a/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h +++ b/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h @@ -22,6 +22,7 @@ #include "llvm/IR/IntrinsicInst.h" #include "llvm/IR/Operator.h" #include "llvm/IR/PatternMatch.h" +#include <optional> #include <utility> namespace llvm { @@ -430,8 +431,8 @@ class TargetTransformInfoImplBase { unsigned getMinVectorRegisterBitWidth() const { return 128; } - Optional<unsigned> getMaxVScale() const { return None; } - Optional<unsigned> getVScaleForTuning() const { return None; } + std::optional<unsigned> getMaxVScale() const { return std::nullopt; } + std::optional<unsigned> getVScaleForTuning() const { return std::nullopt; } bool shouldMaximizeVectorBandwidth(TargetTransformInfo::RegisterKind K) const { diff --git a/llvm/include/llvm/AsmParser/LLParser.h b/llvm/include/llvm/AsmParser/LLParser.h index d936c6f36b6f5..321b02c70cd39 100644 --- a/llvm/include/llvm/AsmParser/LLParser.h +++ b/llvm/include/llvm/AsmParser/LLParser.h @@ -21,6 +21,7 @@ #include "llvm/IR/Instructions.h" #include "llvm/IR/ModuleSummaryIndex.h" #include <map> +#include <optional> namespace llvm { class Module; @@ -301,7 +302,7 @@ namespace llvm { bool parseOptionalCommaAddrSpace(unsigned &AddrSpace, LocTy &Loc, bool &AteExtraComma); bool parseAllocSizeArguments(unsigned &BaseSizeArg, - Optional<unsigned> &HowManyArg); + std::optional<unsigned> &HowManyArg); bool parseVScaleRangeArguments(unsigned &MinValue, unsigned &MaxValue); bool parseIndexList(SmallVectorImpl<unsigned> &Indices, bool &AteExtraComma); diff --git a/llvm/include/llvm/CodeGen/BasicTTIImpl.h b/llvm/include/llvm/CodeGen/BasicTTIImpl.h index 3554c31a4f2f6..5786310aba00b 100644 --- a/llvm/include/llvm/CodeGen/BasicTTIImpl.h +++ b/llvm/include/llvm/CodeGen/BasicTTIImpl.h @@ -52,6 +52,7 @@ #include <cassert> #include <cstdint> #include <limits> +#include <optional> #include <utility> namespace llvm { @@ -698,8 +699,8 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> { return TypeSize::getFixed(32); } - Optional<unsigned> getMaxVScale() const { return None; } - Optional<unsigned> getVScaleForTuning() const { return None; } + std::optional<unsigned> getMaxVScale() const { return std::nullopt; } + std::optional<unsigned> getVScaleForTuning() const { return std::nullopt; } /// Estimate the overhead of scalarizing an instruction. Insert and Extract /// are set if the demanded result elements need to be inserted and/or diff --git a/llvm/include/llvm/IR/Attributes.h b/llvm/include/llvm/IR/Attributes.h index e2db9c6e80adc..505b42b948ff4 100644 --- a/llvm/include/llvm/IR/Attributes.h +++ b/llvm/include/llvm/IR/Attributes.h @@ -18,7 +18,6 @@ #include "llvm-c/Types.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/BitmaskEnum.h" -#include "llvm/ADT/Optional.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringRef.h" #include "llvm/Config/llvm-config.h" @@ -28,6 +27,7 @@ #include <bitset> #include <cassert> #include <cstdint> +#include <optional> #include <set> #include <string> #include <utility> @@ -135,9 +135,9 @@ class Attribute { uint64_t Bytes); static Attribute getWithDereferenceableOrNullBytes(LLVMContext &Context, uint64_t Bytes); - static Attribute getWithAllocSizeArgs(LLVMContext &Context, - unsigned ElemSizeArg, - const Optional<unsigned> &NumElemsArg); + static Attribute getWithAllocSizeArgs( + LLVMContext &Context, unsigned ElemSizeArg, + const std::optional<unsigned> &NumElemsArg); static Attribute getWithVScaleRangeArgs(LLVMContext &Context, unsigned MinValue, unsigned MaxValue); static Attribute getWithByValType(LLVMContext &Context, Type *Ty); @@ -230,14 +230,14 @@ class Attribute { uint64_t getDereferenceableOrNullBytes() const; /// Returns the argument numbers for the allocsize attribute. - std::pair<unsigned, Optional<unsigned>> getAllocSizeArgs() const; + std::pair<unsigned, std::optional<unsigned>> getAllocSizeArgs() const; /// Returns the minimum value for the vscale_range attribute. unsigned getVScaleRangeMin() const; /// Returns the maximum value for the vscale_range attribute or None when /// unknown. - Optional<unsigned> getVScaleRangeMax() const; + std::optional<unsigned> getVScaleRangeMax() const; // Returns the unwind table kind. UWTableKind getUWTableKind() const; @@ -375,9 +375,10 @@ class AttributeSet { Type *getPreallocatedType() const; Type *getInAllocaType() const; Type *getElementType() const; - Optional<std::pair<unsigned, Optional<unsigned>>> getAllocSizeArgs() const; + std::optional<std::pair<unsigned, std::optional<unsigned>>> getAllocSizeArgs() + const; unsigned getVScaleRangeMin() const; - Optional<unsigned> getVScaleRangeMax() const; + std::optional<unsigned> getVScaleRangeMax() const; UWTableKind getUWTableKind() const; AllocFnKind getAllocKind() const; MemoryEffects getMemoryEffects() const; @@ -730,7 +731,7 @@ class AttributeList { /// Returns a new list because attribute lists are immutable. [[nodiscard]] AttributeList addAllocSizeParamAttr(LLVMContext &C, unsigned ArgNo, unsigned ElemSizeArg, - const Optional<unsigned> &NumElemsArg); + const std::optional<unsigned> &NumElemsArg); //===--------------------------------------------------------------------===// // AttributeList Accessors @@ -1106,7 +1107,7 @@ class AttrBuilder { /// Return raw (possibly packed/encoded) value of integer attribute or None if /// not set. - Optional<uint64_t> getRawIntAttr(Attribute::AttrKind Kind) const; + std::optional<uint64_t> getRawIntAttr(Attribute::AttrKind Kind) const; /// Retrieve the alignment attribute, if it exists. MaybeAlign getAlignment() const { @@ -1151,7 +1152,8 @@ class AttrBuilder { Type *getInAllocaType() const { return getTypeAttr(Attribute::InAlloca); } /// Retrieve the allocsize args, or None if the attribute does not exist. - Optional<std::pair<unsigned, Optional<unsigned>>> getAllocSizeArgs() const; + std::optional<std::pair<unsigned, std::optional<unsigned>>> getAllocSizeArgs() + const; /// Add integer attribute with raw value (packed/encoded if necessary). AttrBuilder &addRawIntAttr(Attribute::AttrKind Kind, uint64_t Value); @@ -1190,11 +1192,11 @@ class AttrBuilder { /// This turns one (or two) ints into the form used internally in Attribute. AttrBuilder &addAllocSizeAttr(unsigned ElemSizeArg, - const Optional<unsigned> &NumElemsArg); + const std::optional<unsigned> &NumElemsArg); /// This turns two ints into the form used internally in Attribute. AttrBuilder &addVScaleRangeAttr(unsigned MinValue, - Optional<unsigned> MaxValue); + std::optional<unsigned> MaxValue); /// Add a type attribute with the given type. AttrBuilder &addTypeAttr(Attribute::AttrKind Kind, Type *Ty); diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp index 77687abd87b9b..43d7368b39710 100644 --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -41,6 +41,7 @@ #include "llvm/IR/PatternMatch.h" #include "llvm/Support/KnownBits.h" #include <algorithm> +#include <optional> using namespace llvm; using namespace llvm::PatternMatch; @@ -6219,7 +6220,7 @@ static Value *simplifyIntrinsic(CallBase *Call, const SimplifyQuery &Q) { if (!Attr.isValid()) return nullptr; unsigned VScaleMin = Attr.getVScaleRangeMin(); - Optional<unsigned> VScaleMax = Attr.getVScaleRangeMax(); + std::optional<unsigned> VScaleMax = Attr.getVScaleRangeMax(); if (VScaleMax && VScaleMin == VScaleMax) return ConstantInt::get(F->getReturnType(), VScaleMin); return nullptr; diff --git a/llvm/lib/Analysis/MemoryBuiltins.cpp b/llvm/lib/Analysis/MemoryBuiltins.cpp index 1cba0571f1fcc..9deb96661f3e9 100644 --- a/llvm/lib/Analysis/MemoryBuiltins.cpp +++ b/llvm/lib/Analysis/MemoryBuiltins.cpp @@ -44,6 +44,7 @@ #include <cstdint> #include <iterator> #include <numeric> +#include <optional> #include <type_traits> #include <utility> @@ -251,7 +252,7 @@ static Optional<AllocFnsTy> getAllocationSize(const Value *V, if (Attr == Attribute()) return None; - std::pair<unsigned, Optional<unsigned>> Args = Attr.getAllocSizeArgs(); + std::pair<unsigned, std::optional<unsigned>> Args = Attr.getAllocSizeArgs(); AllocFnsTy Result; // Because allocsize only tells us how many bytes are allocated, we're not diff --git a/llvm/lib/Analysis/TargetTransformInfo.cpp b/llvm/lib/Analysis/TargetTransformInfo.cpp index c6f6bb499bc21..e8e8305db3bdf 100644 --- a/llvm/lib/Analysis/TargetTransformInfo.cpp +++ b/llvm/lib/Analysis/TargetTransformInfo.cpp @@ -650,11 +650,11 @@ unsigned TargetTransformInfo::getMinVectorRegisterBitWidth() const { return TTIImpl->getMinVectorRegisterBitWidth(); } -Optional<unsigned> TargetTransformInfo::getMaxVScale() const { +std::optional<unsigned> TargetTransformInfo::getMaxVScale() const { return TTIImpl->getMaxVScale(); } -Optional<unsigned> TargetTransformInfo::getVScaleForTuning() const { +std::optional<unsigned> TargetTransformInfo::getVScaleForTuning() const { return TTIImpl->getVScaleForTuning(); } diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index 28463bb074f2b..f29b0f8e634ef 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -1747,7 +1747,7 @@ static void computeKnownBitsFromOperator(const Operator *I, break; auto Attr = II->getFunction()->getFnAttribute(Attribute::VScaleRange); - Optional<unsigned> VScaleMax = Attr.getVScaleRangeMax(); + std::optional<unsigned> VScaleMax = Attr.getVScaleRangeMax(); if (!VScaleMax) break; diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp index dde0672da8e48..4c80a199fc73b 100644 --- a/llvm/lib/AsmParser/LLParser.cpp +++ b/llvm/lib/AsmParser/LLParser.cpp @@ -50,6 +50,7 @@ #include <algorithm> #include <cassert> #include <cstring> +#include <optional> #include <vector> using namespace llvm; @@ -1427,7 +1428,7 @@ bool LLParser::parseEnumAttribute(Attribute::AttrKind Attr, AttrBuilder &B, } case Attribute::AllocSize: { unsigned ElemSizeArg; - Optional<unsigned> NumElemsArg; + std::optional<unsigned> NumElemsArg; if (parseAllocSizeArguments(ElemSizeArg, NumElemsArg)) return true; B.addAllocSizeAttr(ElemSizeArg, NumElemsArg); @@ -1438,7 +1439,7 @@ bool LLParser::parseEnumAttribute(Attribute::AttrKind Attr, AttrBuilder &B, if (parseVScaleRangeArguments(MinValue, MaxValue)) return true; B.addVScaleRangeAttr(MinValue, - MaxValue > 0 ? MaxValue : Optional<unsigned>()); + MaxValue > 0 ? MaxValue : std::optional<unsigned>()); return false; } case Attribute::Dereferenceable: { @@ -2371,7 +2372,7 @@ bool LLParser::parseOptionalCommaAddrSpace(unsigned &AddrSpace, LocTy &Loc, } bool LLParser::parseAllocSizeArguments(unsigned &BaseSizeArg, - Optional<unsigned> &HowManyArg) { + std::optional<unsigned> &HowManyArg) { Lex.Lex(); auto StartParen = Lex.getLoc(); diff --git a/llvm/lib/IR/AttributeImpl.h b/llvm/lib/IR/AttributeImpl.h index 86ddb683f9ee1..fd5bdf7415a43 100644 --- a/llvm/lib/IR/AttributeImpl.h +++ b/llvm/lib/IR/AttributeImpl.h @@ -24,6 +24,7 @@ #include <cassert> #include <cstddef> #include <cstdint> +#include <optional> #include <string> #include <utility> @@ -229,7 +230,7 @@ class AttributeSetNode final static AttributeSetNode *getSorted(LLVMContext &C, ArrayRef<Attribute> SortedAttrs); - Optional<Attribute> findEnumAttribute(Attribute::AttrKind Kind) const; + std::optional<Attribute> findEnumAttribute(Attribute::AttrKind Kind) const; public: // AttributesSetNode is uniqued, these should not be available. @@ -258,9 +259,10 @@ class AttributeSetNode final MaybeAlign getStackAlignment() const; uint64_t getDereferenceableBytes() const; uint64_t getDereferenceableOrNullBytes() const; - Optional<std::pair<unsigned, Optional<unsigned>>> getAllocSizeArgs() const; + std::optional<std::pair<unsigned, std::optional<unsigned>>> getAllocSizeArgs() + const; unsigned getVScaleRangeMin() const; - Optional<unsigned> getVScaleRangeMax() const; + std::optional<unsigned> getVScaleRangeMax() const; UWTableKind getUWTableKind() const; AllocFnKind getAllocKind() const; MemoryEffects getMemoryEffects() const; diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp index 1a90b945eb2bf..e4dee3f4d9b44 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)); } diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp index 11842ef4a169e..610fc317b566e 100644 --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -2130,7 +2130,7 @@ void Verifier::verifyFunctionAttrs(FunctionType *FT, AttributeList Attrs, if (VScaleMin == 0) CheckFailed("'vscale_range' minimum must be greater than 0", V); - Optional<unsigned> VScaleMax = Attrs.getFnAttrs().getVScaleRangeMax(); + std::optional<unsigned> VScaleMax = Attrs.getFnAttrs().getVScaleRangeMax(); if (VScaleMax && VScaleMin > VScaleMax) CheckFailed("'vscale_range' minimum cannot be greater than maximum", V); } diff --git a/llvm/lib/Target/AArch64/AArch64TargetMachine.cpp b/llvm/lib/Target/AArch64/AArch64TargetMachine.cpp index affdadfdde34e..997b662027f61 100644 --- a/llvm/lib/Target/AArch64/AArch64TargetMachine.cpp +++ b/llvm/lib/Target/AArch64/AArch64TargetMachine.cpp @@ -50,6 +50,7 @@ #include "llvm/Transforms/CFGuard.h" #include "llvm/Transforms/Scalar.h" #include <memory> +#include <optional> #include <string> using namespace llvm; @@ -397,7 +398,7 @@ AArch64TargetMachine::getSubtargetImpl(const Function &F) const { unsigned MaxSVEVectorSize = 0; Attribute VScaleRangeAttr = F.getFnAttribute(Attribute::VScaleRange); if (VScaleRangeAttr.isValid()) { - Optional<unsigned> VScaleMax = VScaleRangeAttr.getVScaleRangeMax(); + std::optional<unsigned> VScaleMax = VScaleRangeAttr.getVScaleRangeMax(); MinSVEVectorSize = VScaleRangeAttr.getVScaleRangeMin() * 128; MaxSVEVectorSize = VScaleMax ? *VScaleMax * 128 : 0; } else { diff --git a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.h b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.h index e9a22862f3c38..04e26f1c98cbd 100644 --- a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.h +++ b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.h @@ -25,6 +25,7 @@ #include "llvm/IR/Function.h" #include "llvm/IR/Intrinsics.h" #include <cstdint> +#include <optional> namespace llvm { @@ -126,7 +127,7 @@ class AArch64TTIImpl : public BasicTTIImplBase<AArch64TTIImpl> { return ST->getMinVectorRegisterBitWidth(); } - Optional<unsigned> getVScaleForTuning() const { + std::optional<unsigned> getVScaleForTuning() const { return ST->getVScaleForTuning(); } diff --git a/llvm/lib/Target/AArch64/SVEIntrinsicOpts.cpp b/llvm/lib/Target/AArch64/SVEIntrinsicOpts.cpp index ccb34f367338a..c5a6cb7af405e 100644 --- a/llvm/lib/Target/AArch64/SVEIntrinsicOpts.cpp +++ b/llvm/lib/Target/AArch64/SVEIntrinsicOpts.cpp @@ -34,6 +34,7 @@ #include "llvm/IR/PatternMatch.h" #include "llvm/InitializePasses.h" #include "llvm/Support/Debug.h" +#include <optional> using namespace llvm; using namespace llvm::PatternMatch; @@ -284,7 +285,7 @@ bool SVEIntrinsicOpts::optimizePredicateStore(Instruction *I) { return false; unsigned MinVScale = Attr.getVScaleRangeMin(); - Optional<unsigned> MaxVScale = Attr.getVScaleRangeMax(); + std::optional<unsigned> MaxVScale = Attr.getVScaleRangeMax(); // The transform needs to know the exact runtime length of scalable vectors if (!MaxVScale || MinVScale != MaxVScale) return false; @@ -347,7 +348,7 @@ bool SVEIntrinsicOpts::optimizePredicateLoad(Instruction *I) { return false; unsigned MinVScale = Attr.getVScaleRangeMin(); - Optional<unsigned> MaxVScale = Attr.getVScaleRangeMax(); + std::optional<unsigned> MaxVScale = Attr.getVScaleRangeMax(); // The transform needs to know the exact runtime length of scalable vectors if (!MaxVScale || MinVScale != MaxVScale) return false; diff --git a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp index c2db9747113c4..ef39a93665cb2 100644 --- a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp +++ b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp @@ -13,6 +13,7 @@ #include "llvm/CodeGen/CostTable.h" #include "llvm/CodeGen/TargetLowering.h" #include <cmath> +#include <optional> using namespace llvm; #define DEBUG_TYPE "riscvtti" @@ -196,13 +197,13 @@ bool RISCVTTIImpl::shouldExpandReduction(const IntrinsicInst *II) const { } } -Optional<unsigned> RISCVTTIImpl::getMaxVScale() const { +std::optional<unsigned> RISCVTTIImpl::getMaxVScale() const { if (ST->hasVInstructions()) return ST->getRealMaxVLen() / RISCV::RVVBitsPerBlock; return BaseT::getMaxVScale(); } -Optional<unsigned> RISCVTTIImpl::getVScaleForTuning() const { +std::optional<unsigned> RISCVTTIImpl::getVScaleForTuning() const { if (ST->hasVInstructions()) if (unsigned MinVLen = ST->getRealMinVLen(); MinVLen >= RISCV::RVVBitsPerBlock) diff --git a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h index 36dd86992263d..d13d58a3c1cf7 100644 --- a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h +++ b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h @@ -22,6 +22,7 @@ #include "llvm/Analysis/TargetTransformInfo.h" #include "llvm/CodeGen/BasicTTIImpl.h" #include "llvm/IR/Function.h" +#include <optional> namespace llvm { @@ -79,8 +80,8 @@ class RISCVTTIImpl : public BasicTTIImplBase<RISCVTTIImpl> { return ST->hasVInstructions() ? PredicationStyle::Data : PredicationStyle::None; } - Optional<unsigned> getMaxVScale() const; - Optional<unsigned> getVScaleForTuning() const; + std::optional<unsigned> getMaxVScale() const; + std::optional<unsigned> getVScaleForTuning() const; TypeSize getRegisterBitWidth(TargetTransformInfo::RegisterKind K) const; diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp index d6f6dd5512699..43d359acabc80 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp @@ -18,6 +18,8 @@ #include "llvm/IR/PatternMatch.h" #include "llvm/Support/KnownBits.h" #include "llvm/Transforms/InstCombine/InstCombiner.h" +#include <optional> + using namespace llvm; using namespace PatternMatch; @@ -979,7 +981,7 @@ Instruction *InstCombinerImpl::visitTrunc(TruncInst &Trunc) { Trunc.getFunction()->hasFnAttribute(Attribute::VScaleRange)) { Attribute Attr = Trunc.getFunction()->getFnAttribute(Attribute::VScaleRange); - if (Optional<unsigned> MaxVScale = Attr.getVScaleRangeMax()) { + if (std::optional<unsigned> MaxVScale = Attr.getVScaleRangeMax()) { if (Log2_32(*MaxVScale) < DestWidth) { Value *VScale = Builder.CreateVScale(ConstantInt::get(DestTy, 1)); return replaceInstUsesWith(Trunc, VScale); @@ -1348,7 +1350,7 @@ Instruction *InstCombinerImpl::visitZExt(ZExtInst &CI) { if (CI.getFunction() && CI.getFunction()->hasFnAttribute(Attribute::VScaleRange)) { Attribute Attr = CI.getFunction()->getFnAttribute(Attribute::VScaleRange); - if (Optional<unsigned> MaxVScale = Attr.getVScaleRangeMax()) { + if (std::optional<unsigned> MaxVScale = Attr.getVScaleRangeMax()) { unsigned TypeWidth = Src->getType()->getScalarSizeInBits(); if (Log2_32(*MaxVScale) < TypeWidth) { Value *VScale = Builder.CreateVScale(ConstantInt::get(DestTy, 1)); @@ -1622,7 +1624,7 @@ Instruction *InstCombinerImpl::visitSExt(SExtInst &CI) { if (CI.getFunction() && CI.getFunction()->hasFnAttribute(Attribute::VScaleRange)) { Attribute Attr = CI.getFunction()->getFnAttribute(Attribute::VScaleRange); - if (Optional<unsigned> MaxVScale = Attr.getVScaleRangeMax()) { + if (std::optional<unsigned> MaxVScale = Attr.getVScaleRangeMax()) { if (Log2_32(*MaxVScale) < (SrcBitSize - 1)) { Value *VScale = Builder.CreateVScale(ConstantInt::get(DestTy, 1)); return replaceInstUsesWith(CI, VScale); diff --git a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp index 5fb4ee1cac524..1c8874069c27a 100644 --- a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp +++ b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp @@ -24,6 +24,7 @@ #include "llvm/IR/Module.h" #include "llvm/IR/Type.h" #include "llvm/Support/TypeSize.h" +#include <optional> using namespace llvm; @@ -226,7 +227,7 @@ static bool setAllocatedPointerParam(Function &F, unsigned ArgNo) { } static bool setAllocSize(Function &F, unsigned ElemSizeArg, - Optional<unsigned> NumElemsArg) { + std::optional<unsigned> NumElemsArg) { if (F.hasFnAttribute(Attribute::AllocSize)) return false; F.addFnAttr(Attribute::getWithAllocSizeArgs(F.getContext(), ElemSizeArg, @@ -441,7 +442,7 @@ bool llvm::inferNonMandatoryLibFuncAttrs(Function &F, break; case LibFunc_aligned_alloc: Changed |= setAlignedAllocParam(F, 0); - Changed |= setAllocSize(F, 1, None); + Changed |= setAllocSize(F, 1, std::nullopt); Changed |= setAllocKind(F, AllocFnKind::Alloc | AllocFnKind::Uninitialized | AllocFnKind::Aligned); [[fallthrough]]; case LibFunc_valloc: @@ -450,7 +451,7 @@ bool llvm::inferNonMandatoryLibFuncAttrs(Function &F, Changed |= setAllocFamily(F, TheLibFunc == LibFunc_vec_malloc ? "vec_malloc" : "malloc"); Changed |= setAllocKind(F, AllocFnKind::Alloc | AllocFnKind::Uninitialized); - Changed |= setAllocSize(F, 0, None); + Changed |= setAllocSize(F, 0, std::nullopt); Changed |= setOnlyAccessesInaccessibleMemory(F); Changed |= setRetAndArgsNoUndef(F); Changed |= setDoesNotThrow(F); @@ -516,7 +517,7 @@ bool llvm::inferNonMandatoryLibFuncAttrs(Function &F, Changed |= setAllocFamily(F, "malloc"); Changed |= setAllocKind(F, AllocFnKind::Alloc | AllocFnKind::Aligned | AllocFnKind::Uninitialized); - Changed |= setAllocSize(F, 1, None); + Changed |= setAllocSize(F, 1, std::nullopt); Changed |= setAlignedAllocParam(F, 0); Changed |= setOnlyAccessesInaccessibleMemory(F); Changed |= setRetNoUndef(F); @@ -543,7 +544,7 @@ bool llvm::inferNonMandatoryLibFuncAttrs(Function &F, F, TheLibFunc == LibFunc_vec_realloc ? "vec_malloc" : "malloc"); Changed |= setAllocKind(F, AllocFnKind::Realloc); Changed |= setAllocatedPointerParam(F, 0); - Changed |= setAllocSize(F, 1, None); + Changed |= setAllocSize(F, 1, std::nullopt); Changed |= setOnlyAccessesInaccessibleMemOrArgMem(F); Changed |= setRetNoUndef(F); Changed |= setDoesNotThrow(F); diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 6eb851677c69c..5f4bb5453ab17 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -1581,7 +1581,7 @@ class LoopVectorizationCostModel { /// Convenience function that returns the value of vscale_range iff /// vscale_range.min == vscale_range.max or otherwise returns the value /// returned by the corresponding TLI method. - Optional<unsigned> getVScaleForTuning() const; + std::optional<unsigned> getVScaleForTuning() const; private: unsigned NumPredStores = 0; @@ -4906,7 +4906,7 @@ LoopVectorizationCostModel::getMaxLegalScalableVF(unsigned MaxSafeElements) { return MaxScalableVF; // Limit MaxScalableVF by the maximum safe dependence distance. - Optional<unsigned> MaxVScale = TTI.getMaxVScale(); + std::optional<unsigned> MaxVScale = TTI.getMaxVScale(); if (!MaxVScale && TheFunction->hasFnAttribute(Attribute::VScaleRange)) MaxVScale = TheFunction->getFnAttribute(Attribute::VScaleRange).getVScaleRangeMax(); @@ -5268,7 +5268,7 @@ ElementCount LoopVectorizationCostModel::getMaximizedVFForTarget( return MaxVF; } -Optional<unsigned> LoopVectorizationCostModel::getVScaleForTuning() const { +std::optional<unsigned> LoopVectorizationCostModel::getVScaleForTuning() const { if (TheFunction->hasFnAttribute(Attribute::VScaleRange)) { auto Attr = TheFunction->getFnAttribute(Attribute::VScaleRange); auto Min = Attr.getVScaleRangeMin(); @@ -5304,7 +5304,7 @@ bool LoopVectorizationCostModel::isMoreProfitable( // Improve estimate for the vector width if it is scalable. unsigned EstimatedWidthA = A.Width.getKnownMinValue(); unsigned EstimatedWidthB = B.Width.getKnownMinValue(); - if (Optional<unsigned> VScale = getVScaleForTuning()) { + if (std::optional<unsigned> VScale = getVScaleForTuning()) { if (A.Width.isScalable()) EstimatedWidthA *= VScale.value(); if (B.Width.isScalable()) @@ -5354,7 +5354,7 @@ VectorizationFactor LoopVectorizationCostModel::selectVectorizationFactor( #ifndef NDEBUG unsigned AssumedMinimumVscale = 1; - if (Optional<unsigned> VScale = getVScaleForTuning()) + if (std::optional<unsigned> VScale = getVScaleForTuning()) AssumedMinimumVscale = *VScale; unsigned Width = Candidate.Width.isScalable() @@ -5577,7 +5577,7 @@ LoopVectorizationCostModel::selectEpilogueVectorizationFactor( ElementCount EstimatedRuntimeVF = MainLoopVF; if (MainLoopVF.isScalable()) { EstimatedRuntimeVF = ElementCount::getFixed(MainLoopVF.getKnownMinValue()); - if (Optional<unsigned> VScale = getVScaleForTuning()) + if (std::optional<unsigned> VScale = getVScaleForTuning()) EstimatedRuntimeVF *= *VScale; } @@ -10042,7 +10042,7 @@ static void checkMixedPrecision(Loop *L, OptimizationRemarkEmitter *ORE) { static bool areRuntimeChecksProfitable(GeneratedRTChecks &Checks, VectorizationFactor &VF, - Optional<unsigned> VScale, Loop *L, + std::optional<unsigned> VScale, Loop *L, ScalarEvolution &SE) { InstructionCost CheckCost = Checks.getCost(); if (!CheckCost.isValid()) _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits