Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Attributes: convert Optional to std::optional
  • Loading branch information
Krzysztof Parzyszek committed Dec 2, 2022
1 parent 71f3cac commit 26424c9
Show file tree
Hide file tree
Showing 22 changed files with 114 additions and 93 deletions.
3 changes: 2 additions & 1 deletion clang/lib/CodeGen/CGCall.cpp
Expand Up @@ -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;

Expand Down Expand Up @@ -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(),
Expand Down
12 changes: 6 additions & 6 deletions llvm/include/llvm/Analysis/TargetTransformInfo.h
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down
5 changes: 3 additions & 2 deletions llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion llvm/include/llvm/AsmParser/LLParser.h
Expand Up @@ -21,6 +21,7 @@
#include "llvm/IR/Instructions.h"
#include "llvm/IR/ModuleSummaryIndex.h"
#include <map>
#include <optional>

namespace llvm {
class Module;
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions llvm/include/llvm/CodeGen/BasicTTIImpl.h
Expand Up @@ -52,6 +52,7 @@
#include <cassert>
#include <cstdint>
#include <limits>
#include <optional>
#include <utility>

namespace llvm {
Expand Down Expand Up @@ -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
Expand Down
28 changes: 15 additions & 13 deletions llvm/include/llvm/IR/Attributes.h
Expand Up @@ -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"
Expand All @@ -28,6 +27,7 @@
#include <bitset>
#include <cassert>
#include <cstdint>
#include <optional>
#include <set>
#include <string>
#include <utility>
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/Analysis/InstructionSimplify.cpp
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/Analysis/MemoryBuiltins.cpp
Expand Up @@ -44,6 +44,7 @@
#include <cstdint>
#include <iterator>
#include <numeric>
#include <optional>
#include <type_traits>
#include <utility>

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Analysis/TargetTransformInfo.cpp
Expand Up @@ -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();
}

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Analysis/ValueTracking.cpp
Expand Up @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions llvm/lib/AsmParser/LLParser.cpp
Expand Up @@ -50,6 +50,7 @@
#include <algorithm>
#include <cassert>
#include <cstring>
#include <optional>
#include <vector>

using namespace llvm;
Expand Down Expand Up @@ -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);
Expand All @@ -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: {
Expand Down Expand Up @@ -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();
Expand Down
8 changes: 5 additions & 3 deletions llvm/lib/IR/AttributeImpl.h
Expand Up @@ -24,6 +24,7 @@
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <optional>
#include <string>
#include <utility>

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 26424c9

Please sign in to comment.