Skip to content

Commit e03f427

Browse files
authored
[LLVM] Use {} instead of std::nullopt to initialize empty ArrayRef (#109133)
It is almost always simpler to use {} instead of std::nullopt to initialize an empty ArrayRef. This patch changes all occurrences I could find in LLVM itself. In future the ArrayRef(std::nullopt_t) constructor could be deprecated or removed.
1 parent 1412022 commit e03f427

File tree

108 files changed

+362
-420
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+362
-420
lines changed

llvm/include/llvm/ADT/TinyPtrVector.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ class TinyPtrVector {
135135
// implicit conversion operator to ArrayRef.
136136
operator ArrayRef<EltTy>() const {
137137
if (Val.isNull())
138-
return std::nullopt;
138+
return {};
139139
if (isa<EltTy>(Val))
140140
return *Val.getAddrOfPtr1();
141141
return *cast<VecTy *>(Val);
@@ -144,7 +144,7 @@ class TinyPtrVector {
144144
// implicit conversion operator to MutableArrayRef.
145145
operator MutableArrayRef<EltTy>() {
146146
if (Val.isNull())
147-
return std::nullopt;
147+
return {};
148148
if (isa<EltTy>(Val))
149149
return *Val.getAddrOfPtr1();
150150
return *cast<VecTy *>(Val);

llvm/include/llvm/Analysis/ScalarEvolution.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,11 +1130,10 @@ class ScalarEvolution {
11301130
/// as arguments and asserts enforce that internally.
11311131
/*implicit*/ ExitLimit(const SCEV *E);
11321132

1133-
ExitLimit(
1134-
const SCEV *E, const SCEV *ConstantMaxNotTaken,
1135-
const SCEV *SymbolicMaxNotTaken, bool MaxOrZero,
1136-
ArrayRef<const SmallPtrSetImpl<const SCEVPredicate *> *> PredSetList =
1137-
std::nullopt);
1133+
ExitLimit(const SCEV *E, const SCEV *ConstantMaxNotTaken,
1134+
const SCEV *SymbolicMaxNotTaken, bool MaxOrZero,
1135+
ArrayRef<const SmallPtrSetImpl<const SCEVPredicate *> *>
1136+
PredSetList = {});
11381137

11391138
ExitLimit(const SCEV *E, const SCEV *ConstantMaxNotTaken,
11401139
const SCEV *SymbolicMaxNotTaken, bool MaxOrZero,

llvm/include/llvm/Analysis/TargetTransformInfo.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,8 +1279,7 @@ class TargetTransformInfo {
12791279
TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput,
12801280
TTI::OperandValueInfo Opd1Info = {TTI::OK_AnyValue, TTI::OP_None},
12811281
TTI::OperandValueInfo Opd2Info = {TTI::OK_AnyValue, TTI::OP_None},
1282-
ArrayRef<const Value *> Args = std::nullopt,
1283-
const Instruction *CxtI = nullptr,
1282+
ArrayRef<const Value *> Args = {}, const Instruction *CxtI = nullptr,
12841283
const TargetLibraryInfo *TLibInfo = nullptr) const;
12851284

12861285
/// Returns the cost estimation for alternating opcode pattern that can be
@@ -1303,11 +1302,12 @@ class TargetTransformInfo {
13031302
/// passed through \p Args, which helps improve the cost estimation in some
13041303
/// cases, like in broadcast loads.
13051304
/// NOTE: For subvector extractions Tp represents the source type.
1306-
InstructionCost getShuffleCost(
1307-
ShuffleKind Kind, VectorType *Tp, ArrayRef<int> Mask = std::nullopt,
1308-
TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput, int Index = 0,
1309-
VectorType *SubTp = nullptr, ArrayRef<const Value *> Args = std::nullopt,
1310-
const Instruction *CxtI = nullptr) const;
1305+
InstructionCost
1306+
getShuffleCost(ShuffleKind Kind, VectorType *Tp, ArrayRef<int> Mask = {},
1307+
TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput,
1308+
int Index = 0, VectorType *SubTp = nullptr,
1309+
ArrayRef<const Value *> Args = {},
1310+
const Instruction *CxtI = nullptr) const;
13111311

13121312
/// Represents a hint about the context in which a cast is used.
13131313
///

llvm/include/llvm/Analysis/TargetTransformInfoImpl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ class TargetTransformInfoImplBase {
605605
ArrayRef<int> Mask,
606606
TTI::TargetCostKind CostKind, int Index,
607607
VectorType *SubTp,
608-
ArrayRef<const Value *> Args = std::nullopt,
608+
ArrayRef<const Value *> Args = {},
609609
const Instruction *CxtI = nullptr) const {
610610
return 1;
611611
}
@@ -1176,7 +1176,7 @@ class TargetTransformInfoImplCRTPBase : public TargetTransformInfoImplBase {
11761176
Cost += static_cast<T *>(this)->getArithmeticInstrCost(
11771177
Instruction::Add, GEP->getType(), CostKind,
11781178
{TTI::OK_AnyValue, TTI::OP_None}, {TTI::OK_AnyValue, TTI::OP_None},
1179-
std::nullopt);
1179+
{});
11801180
} else {
11811181
SmallVector<const Value *> Indices(GEP->indices());
11821182
Cost += static_cast<T *>(this)->getGEPCost(GEP->getSourceElementType(),

llvm/include/llvm/CodeGen/BasicTTIImpl.h

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -897,8 +897,7 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
897897
unsigned Opcode, Type *Ty, TTI::TargetCostKind CostKind,
898898
TTI::OperandValueInfo Opd1Info = {TTI::OK_AnyValue, TTI::OP_None},
899899
TTI::OperandValueInfo Opd2Info = {TTI::OK_AnyValue, TTI::OP_None},
900-
ArrayRef<const Value *> Args = std::nullopt,
901-
const Instruction *CxtI = nullptr) {
900+
ArrayRef<const Value *> Args = {}, const Instruction *CxtI = nullptr) {
902901
// Check if any of the operands are vector operands.
903902
const TargetLoweringBase *TLI = getTLI();
904903
int ISD = TLI->InstructionOpcodeToISD(Opcode);
@@ -1023,7 +1022,7 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
10231022
ArrayRef<int> Mask,
10241023
TTI::TargetCostKind CostKind, int Index,
10251024
VectorType *SubTp,
1026-
ArrayRef<const Value *> Args = std::nullopt,
1025+
ArrayRef<const Value *> Args = {},
10271026
const Instruction *CxtI = nullptr) {
10281027
switch (improveShuffleKindFromMask(Kind, Mask, Tp, Index, SubTp)) {
10291028
case TTI::SK_Broadcast:
@@ -1657,9 +1656,9 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
16571656
if (isa<ScalableVectorType>(RetTy))
16581657
return BaseT::getIntrinsicInstrCost(ICA, CostKind);
16591658
unsigned Index = cast<ConstantInt>(Args[1])->getZExtValue();
1660-
return thisT()->getShuffleCost(
1661-
TTI::SK_ExtractSubvector, cast<VectorType>(Args[0]->getType()),
1662-
std::nullopt, CostKind, Index, cast<VectorType>(RetTy));
1659+
return thisT()->getShuffleCost(TTI::SK_ExtractSubvector,
1660+
cast<VectorType>(Args[0]->getType()), {},
1661+
CostKind, Index, cast<VectorType>(RetTy));
16631662
}
16641663
case Intrinsic::vector_insert: {
16651664
// FIXME: Handle case where a scalable vector is inserted into a scalable
@@ -1668,19 +1667,19 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
16681667
return BaseT::getIntrinsicInstrCost(ICA, CostKind);
16691668
unsigned Index = cast<ConstantInt>(Args[2])->getZExtValue();
16701669
return thisT()->getShuffleCost(
1671-
TTI::SK_InsertSubvector, cast<VectorType>(Args[0]->getType()),
1672-
std::nullopt, CostKind, Index, cast<VectorType>(Args[1]->getType()));
1670+
TTI::SK_InsertSubvector, cast<VectorType>(Args[0]->getType()), {},
1671+
CostKind, Index, cast<VectorType>(Args[1]->getType()));
16731672
}
16741673
case Intrinsic::vector_reverse: {
1675-
return thisT()->getShuffleCost(
1676-
TTI::SK_Reverse, cast<VectorType>(Args[0]->getType()), std::nullopt,
1677-
CostKind, 0, cast<VectorType>(RetTy));
1674+
return thisT()->getShuffleCost(TTI::SK_Reverse,
1675+
cast<VectorType>(Args[0]->getType()), {},
1676+
CostKind, 0, cast<VectorType>(RetTy));
16781677
}
16791678
case Intrinsic::vector_splice: {
16801679
unsigned Index = cast<ConstantInt>(Args[2])->getZExtValue();
1681-
return thisT()->getShuffleCost(
1682-
TTI::SK_Splice, cast<VectorType>(Args[0]->getType()), std::nullopt,
1683-
CostKind, Index, cast<VectorType>(RetTy));
1680+
return thisT()->getShuffleCost(TTI::SK_Splice,
1681+
cast<VectorType>(Args[0]->getType()), {},
1682+
CostKind, Index, cast<VectorType>(RetTy));
16841683
}
16851684
case Intrinsic::vector_reduce_add:
16861685
case Intrinsic::vector_reduce_mul:
@@ -2600,9 +2599,8 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
26002599
while (NumVecElts > MVTLen) {
26012600
NumVecElts /= 2;
26022601
VectorType *SubTy = FixedVectorType::get(ScalarTy, NumVecElts);
2603-
ShuffleCost +=
2604-
thisT()->getShuffleCost(TTI::SK_ExtractSubvector, Ty, std::nullopt,
2605-
CostKind, NumVecElts, SubTy);
2602+
ShuffleCost += thisT()->getShuffleCost(TTI::SK_ExtractSubvector, Ty, {},
2603+
CostKind, NumVecElts, SubTy);
26062604
ArithCost += thisT()->getArithmeticInstrCost(Opcode, SubTy, CostKind);
26072605
Ty = SubTy;
26082606
++LongVectorCount;
@@ -2618,7 +2616,7 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
26182616
// By default reductions need one shuffle per reduction level.
26192617
ShuffleCost +=
26202618
NumReduxLevels * thisT()->getShuffleCost(TTI::SK_PermuteSingleSrc, Ty,
2621-
std::nullopt, CostKind, 0, Ty);
2619+
{}, CostKind, 0, Ty);
26222620
ArithCost +=
26232621
NumReduxLevels * thisT()->getArithmeticInstrCost(Opcode, Ty, CostKind);
26242622
return ShuffleCost + ArithCost +
@@ -2691,9 +2689,8 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
26912689
NumVecElts /= 2;
26922690
auto *SubTy = FixedVectorType::get(ScalarTy, NumVecElts);
26932691

2694-
ShuffleCost +=
2695-
thisT()->getShuffleCost(TTI::SK_ExtractSubvector, Ty, std::nullopt,
2696-
CostKind, NumVecElts, SubTy);
2692+
ShuffleCost += thisT()->getShuffleCost(TTI::SK_ExtractSubvector, Ty, {},
2693+
CostKind, NumVecElts, SubTy);
26972694

26982695
IntrinsicCostAttributes Attrs(IID, SubTy, {SubTy, SubTy}, FMF);
26992696
MinMaxCost += getIntrinsicInstrCost(Attrs, CostKind);
@@ -2709,7 +2706,7 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
27092706
// architecture-dependent length.
27102707
ShuffleCost +=
27112708
NumReduxLevels * thisT()->getShuffleCost(TTI::SK_PermuteSingleSrc, Ty,
2712-
std::nullopt, CostKind, 0, Ty);
2709+
{}, CostKind, 0, Ty);
27132710
IntrinsicCostAttributes Attrs(IID, Ty, {Ty, Ty}, FMF);
27142711
MinMaxCost += NumReduxLevels * getIntrinsicInstrCost(Attrs, CostKind);
27152712
// The last min/max should be in vector registers and we counted it above.

llvm/include/llvm/CodeGen/GlobalISel/CallLowering.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -409,20 +409,21 @@ class CallLowering {
409409
/// \p Handler to move them to the assigned locations.
410410
///
411411
/// \return True if everything has succeeded, false otherwise.
412-
bool determineAndHandleAssignments(
413-
ValueHandler &Handler, ValueAssigner &Assigner,
414-
SmallVectorImpl<ArgInfo> &Args, MachineIRBuilder &MIRBuilder,
415-
CallingConv::ID CallConv, bool IsVarArg,
416-
ArrayRef<Register> ThisReturnRegs = std::nullopt) const;
412+
bool
413+
determineAndHandleAssignments(ValueHandler &Handler, ValueAssigner &Assigner,
414+
SmallVectorImpl<ArgInfo> &Args,
415+
MachineIRBuilder &MIRBuilder,
416+
CallingConv::ID CallConv, bool IsVarArg,
417+
ArrayRef<Register> ThisReturnRegs = {}) const;
417418

418419
/// Use \p Handler to insert code to handle the argument/return values
419420
/// represented by \p Args. It's expected determineAssignments previously
420421
/// processed these arguments to populate \p CCState and \p ArgLocs.
421-
bool
422-
handleAssignments(ValueHandler &Handler, SmallVectorImpl<ArgInfo> &Args,
423-
CCState &CCState, SmallVectorImpl<CCValAssign> &ArgLocs,
424-
MachineIRBuilder &MIRBuilder,
425-
ArrayRef<Register> ThisReturnRegs = std::nullopt) const;
422+
bool handleAssignments(ValueHandler &Handler, SmallVectorImpl<ArgInfo> &Args,
423+
CCState &CCState,
424+
SmallVectorImpl<CCValAssign> &ArgLocs,
425+
MachineIRBuilder &MIRBuilder,
426+
ArrayRef<Register> ThisReturnRegs = {}) const;
426427

427428
/// Check whether parameters to a call that are passed in callee saved
428429
/// registers are the same as from the calling function. This needs to be

llvm/include/llvm/CodeGen/LiveRangeEdit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ class LiveRangeEdit : private MachineRegisterInfo::Delegate {
237237
/// allocator. These registers should not be split into new intervals
238238
/// as currently those new intervals are not guaranteed to spill.
239239
void eliminateDeadDefs(SmallVectorImpl<MachineInstr *> &Dead,
240-
ArrayRef<Register> RegsBeingSpilled = std::nullopt);
240+
ArrayRef<Register> RegsBeingSpilled = {});
241241

242242
/// calculateRegClassAndHint - Recompute register class and hint for each new
243243
/// register.

llvm/include/llvm/CodeGen/MachineTraceMetrics.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,9 @@ class MachineTraceMetrics : public MachineFunctionPass {
295295
/// classes are included. For the caller to account for extra machine
296296
/// instructions, it must first resolve each instruction's scheduling class.
297297
unsigned getResourceLength(
298-
ArrayRef<const MachineBasicBlock *> Extrablocks = std::nullopt,
299-
ArrayRef<const MCSchedClassDesc *> ExtraInstrs = std::nullopt,
300-
ArrayRef<const MCSchedClassDesc *> RemoveInstrs = std::nullopt) const;
298+
ArrayRef<const MachineBasicBlock *> Extrablocks = {},
299+
ArrayRef<const MCSchedClassDesc *> ExtraInstrs = {},
300+
ArrayRef<const MCSchedClassDesc *> RemoveInstrs = {}) const;
301301

302302
/// Return the length of the (data dependency) critical path through the
303303
/// trace.

llvm/include/llvm/CodeGen/TargetInstrInfo.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2007,7 +2007,7 @@ class TargetInstrInfo : public MCInstrInfo {
20072007
/// defined by this method.
20082008
virtual ArrayRef<std::pair<int, const char *>>
20092009
getSerializableTargetIndices() const {
2010-
return std::nullopt;
2010+
return {};
20112011
}
20122012

20132013
/// Decompose the machine operand's target flags into two values - the direct
@@ -2024,7 +2024,7 @@ class TargetInstrInfo : public MCInstrInfo {
20242024
/// defined by this method.
20252025
virtual ArrayRef<std::pair<unsigned, const char *>>
20262026
getSerializableDirectMachineOperandTargetFlags() const {
2027-
return std::nullopt;
2027+
return {};
20282028
}
20292029

20302030
/// Return an array that contains the bitmask target flag values and their
@@ -2034,7 +2034,7 @@ class TargetInstrInfo : public MCInstrInfo {
20342034
/// defined by this method.
20352035
virtual ArrayRef<std::pair<unsigned, const char *>>
20362036
getSerializableBitmaskMachineOperandTargetFlags() const {
2037-
return std::nullopt;
2037+
return {};
20382038
}
20392039

20402040
/// Return an array that contains the MMO target flag values and their
@@ -2044,7 +2044,7 @@ class TargetInstrInfo : public MCInstrInfo {
20442044
/// defined by this method.
20452045
virtual ArrayRef<std::pair<MachineMemOperand::Flags, const char *>>
20462046
getSerializableMachineMemOperandTargetFlags() const {
2047-
return std::nullopt;
2047+
return {};
20482048
}
20492049

20502050
/// Determines whether \p Inst is a tail call instruction. Override this

llvm/include/llvm/IR/DIBuilder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ namespace llvm {
772772
/// Create a new descriptor for the specified
773773
/// variable which has a complex address expression for its address.
774774
/// \param Addr An array of complex address operations.
775-
DIExpression *createExpression(ArrayRef<uint64_t> Addr = std::nullopt);
775+
DIExpression *createExpression(ArrayRef<uint64_t> Addr = {});
776776

777777
/// Create an expression for a variable that does not have an address, but
778778
/// does have a constant value.

llvm/include/llvm/IR/DebugInfoMetadata.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ class DINode : public MDNode {
138138

139139
protected:
140140
DINode(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
141-
ArrayRef<Metadata *> Ops1, ArrayRef<Metadata *> Ops2 = std::nullopt)
141+
ArrayRef<Metadata *> Ops1, ArrayRef<Metadata *> Ops2 = {})
142142
: MDNode(C, ID, Storage, Ops1, Ops2) {
143143
assert(Tag < 1u << 16);
144144
SubclassData16 = Tag;
@@ -311,7 +311,7 @@ class DIAssignID : public MDNode {
311311
friend class MDNode;
312312

313313
DIAssignID(LLVMContext &C, StorageType Storage)
314-
: MDNode(C, DIAssignIDKind, Storage, std::nullopt) {}
314+
: MDNode(C, DIAssignIDKind, Storage, {}) {}
315315

316316
~DIAssignID() { dropAllReferences(); }
317317

@@ -2730,7 +2730,7 @@ class DIExpression : public MDNode {
27302730
std::vector<uint64_t> Elements;
27312731

27322732
DIExpression(LLVMContext &C, StorageType Storage, ArrayRef<uint64_t> Elements)
2733-
: MDNode(C, DIExpressionKind, Storage, std::nullopt),
2733+
: MDNode(C, DIExpressionKind, Storage, {}),
27342734
Elements(Elements.begin(), Elements.end()) {}
27352735
~DIExpression() = default;
27362736

@@ -3776,8 +3776,7 @@ class DIMacroNode : public MDNode {
37763776

37773777
protected:
37783778
DIMacroNode(LLVMContext &C, unsigned ID, StorageType Storage, unsigned MIType,
3779-
ArrayRef<Metadata *> Ops1,
3780-
ArrayRef<Metadata *> Ops2 = std::nullopt)
3779+
ArrayRef<Metadata *> Ops1, ArrayRef<Metadata *> Ops2 = {})
37813780
: MDNode(C, ID, Storage, Ops1, Ops2) {
37823781
assert(MIType < 1u << 16);
37833782
SubclassData16 = MIType;

llvm/include/llvm/IR/DerivedTypes.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -733,16 +733,16 @@ class TargetExtType : public Type {
733733
/// Return a target extension type having the specified name and optional
734734
/// type and integer parameters.
735735
static TargetExtType *get(LLVMContext &Context, StringRef Name,
736-
ArrayRef<Type *> Types = std::nullopt,
737-
ArrayRef<unsigned> Ints = std::nullopt);
736+
ArrayRef<Type *> Types = {},
737+
ArrayRef<unsigned> Ints = {});
738738

739739
/// Return a target extension type having the specified name and optional
740740
/// type and integer parameters, or an appropriate Error if it fails the
741741
/// parameters check.
742-
static Expected<TargetExtType *>
743-
getOrError(LLVMContext &Context, StringRef Name,
744-
ArrayRef<Type *> Types = std::nullopt,
745-
ArrayRef<unsigned> Ints = std::nullopt);
742+
static Expected<TargetExtType *> getOrError(LLVMContext &Context,
743+
StringRef Name,
744+
ArrayRef<Type *> Types = {},
745+
ArrayRef<unsigned> Ints = {});
746746

747747
/// Check that a newly created target extension type has the expected number
748748
/// of type parameters and integer parameters, returning the type itself if OK

0 commit comments

Comments
 (0)