51 changes: 23 additions & 28 deletions llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1293,7 +1293,7 @@ class BoUpSLP {

/// \returns the vectorization cost of the subtree that starts at \p VL.
/// A negative number means that this is profitable.
InstructionCost getTreeCost(ArrayRef<Value *> VectorizedVals = std::nullopt);
InstructionCost getTreeCost(ArrayRef<Value *> VectorizedVals = {});

/// Construct a vectorizable tree that starts at \p Roots, ignoring users for
/// the purpose of scheduling and extraction in the \p UserIgnoreLst.
Expand Down Expand Up @@ -1792,7 +1792,7 @@ class BoUpSLP {
// Recursively calculate the cost at each level
int TmpScore =
getScoreAtLevelRec(I1->getOperand(OpIdx1), I2->getOperand(OpIdx2),
I1, I2, CurrLevel + 1, std::nullopt);
I1, I2, CurrLevel + 1, {});
// Look for the best score.
if (TmpScore > LookAheadHeuristics::ScoreFail &&
TmpScore > MaxTmpScore) {
Expand Down Expand Up @@ -2601,7 +2601,7 @@ class BoUpSLP {
int Score = LookAhead.getScoreAtLevelRec(Candidates[I].first,
Candidates[I].second,
/*U1=*/nullptr, /*U2=*/nullptr,
/*CurrLevel=*/1, std::nullopt);
/*CurrLevel=*/1, {});
if (Score > BestScore) {
BestScore = Score;
Index = I;
Expand Down Expand Up @@ -3364,8 +3364,8 @@ class BoUpSLP {
std::optional<ScheduleData *> Bundle,
const InstructionsState &S,
const EdgeInfo &UserTreeIdx,
ArrayRef<int> ReuseShuffleIndices = std::nullopt,
ArrayRef<unsigned> ReorderIndices = std::nullopt) {
ArrayRef<int> ReuseShuffleIndices = {},
ArrayRef<unsigned> ReorderIndices = {}) {
TreeEntry::EntryState EntryState =
Bundle ? TreeEntry::Vectorize : TreeEntry::NeedToGather;
return newTreeEntry(VL, EntryState, Bundle, S, UserTreeIdx,
Expand All @@ -3377,8 +3377,8 @@ class BoUpSLP {
std::optional<ScheduleData *> Bundle,
const InstructionsState &S,
const EdgeInfo &UserTreeIdx,
ArrayRef<int> ReuseShuffleIndices = std::nullopt,
ArrayRef<unsigned> ReorderIndices = std::nullopt) {
ArrayRef<int> ReuseShuffleIndices = {},
ArrayRef<unsigned> ReorderIndices = {}) {
assert(((!Bundle && EntryState == TreeEntry::NeedToGather) ||
(Bundle && EntryState != TreeEntry::NeedToGather)) &&
"Need to vectorize gather entry?");
Expand Down Expand Up @@ -4678,10 +4678,10 @@ getGEPCosts(const TargetTransformInfo &TTI, ArrayRef<Value *> Ptrs,
/// subvector pattern.
static InstructionCost
getShuffleCost(const TargetTransformInfo &TTI, TTI::ShuffleKind Kind,
VectorType *Tp, ArrayRef<int> Mask = std::nullopt,
VectorType *Tp, ArrayRef<int> Mask = {},
TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput,
int Index = 0, VectorType *SubTp = nullptr,
ArrayRef<const Value *> Args = std::nullopt) {
ArrayRef<const Value *> Args = {}) {
if (Kind != TTI::SK_PermuteTwoSrc)
return TTI.getShuffleCost(Kind, Tp, Mask, CostKind, Index, SubTp, Args);
int NumSrcElts = Tp->getElementCount().getKnownMinValue();
Expand Down Expand Up @@ -4841,8 +4841,7 @@ BoUpSLP::LoadsState BoUpSLP::canVectorizeLoads(
TTI.getScalarizationOverhead(
PtrVecTy, APInt::getOneBitSet(VecTy->getNumElements(), 0),
/*Insert=*/true, /*Extract=*/false, CostKind) +
::getShuffleCost(TTI, TTI::SK_Broadcast, PtrVecTy, std::nullopt,
CostKind);
::getShuffleCost(TTI, TTI::SK_Broadcast, PtrVecTy, {}, CostKind);
// The cost of scalar loads.
InstructionCost ScalarLoadsCost =
std::accumulate(VL.begin(), VL.end(), InstructionCost(),
Expand Down Expand Up @@ -4941,7 +4940,7 @@ BoUpSLP::LoadsState BoUpSLP::canVectorizeLoads(
SubVecTy, APInt::getOneBitSet(VF, 0),
/*Insert=*/true, /*Extract=*/false, CostKind) +
::getShuffleCost(TTI, TTI::SK_Broadcast, SubVecTy,
std::nullopt, CostKind);
{}, CostKind);
}
switch (LS) {
case LoadsState::Vectorize:
Expand Down Expand Up @@ -7405,7 +7404,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
if (IsIdentity)
CurrentOrder.clear();
TreeEntry *TE = newTreeEntry(VL, Bundle /*vectorized*/, S, UserTreeIdx,
std::nullopt, CurrentOrder);
{}, CurrentOrder);
LLVM_DEBUG(dbgs() << "SLP: added inserts bundle.\n");

TE->setOperandsInOrder();
Expand Down Expand Up @@ -8756,9 +8755,8 @@ class BoUpSLP::ShuffleCostEstimator : public BaseShuffleAnalysis {
"SK_ExtractSubvector index out of range");
Cost += ::getShuffleCost(
TTI, TTI::SK_ExtractSubvector,
getWidenedType(ScalarTy, alignTo(NumElts, EltsPerVector)),
std::nullopt, CostKind, Idx,
getWidenedType(ScalarTy, EltsPerVector));
getWidenedType(ScalarTy, alignTo(NumElts, EltsPerVector)), {},
CostKind, Idx, getWidenedType(ScalarTy, EltsPerVector));
}
// Second attempt to check, if just a permute is better estimated than
// subvector extract.
Expand Down Expand Up @@ -9411,9 +9409,8 @@ class BoUpSLP::ShuffleCostEstimator : public BaseShuffleAnalysis {
}
Cost += ::getShuffleCost(
TTI, TTI::SK_InsertSubvector,
FixedVectorType::get(ScalarTy, CommonMask.size()), std::nullopt,
CostKind, Idx,
FixedVectorType::get(ScalarTy, E->getVectorFactor()));
FixedVectorType::get(ScalarTy, CommonMask.size()), {}, CostKind,
Idx, FixedVectorType::get(ScalarTy, E->getVectorFactor()));
if (!CommonMask.empty()) {
std::iota(std::next(CommonMask.begin(), Idx),
std::next(CommonMask.begin(), Idx + E->getVectorFactor()),
Expand Down Expand Up @@ -9824,9 +9821,8 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
if (!InMask.all() && NumScalars != NumElts && !IsWholeSubvector) {
if (InsertVecSz != VecSz) {
auto *ActualVecTy = getWidenedType(ScalarTy, VecSz);
Cost += ::getShuffleCost(*TTI, TTI::SK_InsertSubvector, ActualVecTy,
std::nullopt, CostKind, OffsetBeg - Offset,
InsertVecTy);
Cost += ::getShuffleCost(*TTI, TTI::SK_InsertSubvector, ActualVecTy, {},
CostKind, OffsetBeg - Offset, InsertVecTy);
} else {
for (unsigned I = 0, End = OffsetBeg - Offset; I < End; ++I)
Mask[I] = InMask.test(I) ? PoisonMaskElem : I;
Expand Down Expand Up @@ -10021,7 +10017,7 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
TTI::OperandValueInfo Op1Info = getOperandInfo(E->getOperand(0));
TTI::OperandValueInfo Op2Info = getOperandInfo(E->getOperand(OpIdx));
return TTI->getArithmeticInstrCost(ShuffleOrOp, VecTy, CostKind, Op1Info,
Op2Info, std::nullopt, nullptr, TLI) +
Op2Info, {}, nullptr, TLI) +
CommonCost;
};
return GetCostDiff(GetScalarCost, GetVectorCost);
Expand Down Expand Up @@ -12681,7 +12677,7 @@ Value *BoUpSLP::vectorizeOperand(TreeEntry *E, unsigned NodeIdx,
return std::make_pair(VectorizableTree[P.first].get(),
P.second);
});
return ShuffleBuilder.finalize(std::nullopt, SubVectors);
return ShuffleBuilder.finalize({}, SubVectors);
};
Value *V = vectorizeTree(VE, PostponedPHIs);
if (VF * getNumElements(VL[0]->getType()) !=
Expand Down Expand Up @@ -13248,7 +13244,7 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) {
E->ReorderIndices.size());
ShuffleBuilder.add(V, Mask);
} else if (E->State == TreeEntry::StridedVectorize && IsReverseOrder) {
ShuffleBuilder.addOrdered(V, std::nullopt);
ShuffleBuilder.addOrdered(V, {});
} else {
ShuffleBuilder.addOrdered(V, E->ReorderIndices);
}
Expand Down Expand Up @@ -14657,7 +14653,7 @@ BoUpSLP::vectorizeTree(const ExtraValueToDebugLocsMap &ExternallyUsedValues,
ShuffleBuilder.add(V1, CombinedMask1);
if (V2)
ShuffleBuilder.add(V2, CombinedMask2);
return ShuffleBuilder.finalize(std::nullopt, std::nullopt);
return ShuffleBuilder.finalize({}, {});
};

auto &&ResizeToVF = [&CreateShuffle](Value *Vec, ArrayRef<int> Mask,
Expand Down Expand Up @@ -15784,8 +15780,7 @@ bool BoUpSLP::collectValuesToDemote(
return false;
};
auto TryProcessInstruction =
[&](unsigned &BitWidth,
ArrayRef<const TreeEntry *> Operands = std::nullopt,
[&](unsigned &BitWidth, ArrayRef<const TreeEntry *> Operands = {},
function_ref<bool(unsigned, unsigned)> Checker = {}) {
if (Operands.empty()) {
if (!IsTruncRoot)
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2257,8 +2257,7 @@ InstructionCost VPWidenMemoryRecipe::computeCost(ElementCount VF,
return Cost;

return Cost += Ctx.TTI.getShuffleCost(TargetTransformInfo::SK_Reverse,
cast<VectorType>(Ty), std::nullopt,
CostKind, 0);
cast<VectorType>(Ty), {}, CostKind, 0);
}

void VPWidenLoadRecipe::execute(VPTransformState &State) {
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Vectorize/VectorCombine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1560,7 +1560,7 @@ bool VectorCombine::foldShuffleOfCastops(Instruction &I) {
InstructionCost OldCost = CostC0 + CostC1;
OldCost +=
TTI.getShuffleCost(TargetTransformInfo::SK_PermuteTwoSrc, CastDstTy,
OldMask, CostKind, 0, nullptr, std::nullopt, &I);
OldMask, CostKind, 0, nullptr, {}, &I);

InstructionCost NewCost = TTI.getShuffleCost(
TargetTransformInfo::SK_PermuteTwoSrc, CastSrcTy, NewMask, CostKind);
Expand Down
2 changes: 1 addition & 1 deletion llvm/tools/llvm-reduce/deltas/ReduceOpcodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ static bool shouldIgnoreArgument(const Value *V) {

static Value *replaceIntrinsic(Module &M, IntrinsicInst *II,
Intrinsic::ID NewIID,
ArrayRef<Type *> Tys = std::nullopt) {
ArrayRef<Type *> Tys = {}) {
Function *NewFunc = Intrinsic::getDeclaration(&M, NewIID, Tys);
II->setCalledFunction(NewFunc);
return II;
Expand Down
2 changes: 1 addition & 1 deletion llvm/unittests/tools/llvm-mca/MCATestBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class MCATestBase : public ::testing::Test {
/// `llvm-mca` tool to verify result correctness.
/// This function only displays on SummaryView by default.
virtual Error runBaselineMCA(json::Object &Result, ArrayRef<MCInst> Insts,
ArrayRef<mca::View *> Views = std::nullopt,
ArrayRef<mca::View *> Views = {},
const mca::PipelineOptions *PO = nullptr);
};

Expand Down
4 changes: 2 additions & 2 deletions llvm/utils/TableGen/DAGISelMatcherGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -692,8 +692,8 @@ void MatcherGen::EmitResultLeafAsOperand(const TreePatternNode &N,
auto IDOperandNo = NextRecordedOperandNo++;
const Record *ImpDef = Def->getRecords().getDef("IMPLICIT_DEF");
CodeGenInstruction &II = CGP.getTargetInfo().getInstruction(ImpDef);
AddMatcher(new EmitNodeMatcher(II, ResultVT, std::nullopt, false, false,
false, false, -1, IDOperandNo));
AddMatcher(new EmitNodeMatcher(II, ResultVT, {}, false, false, false,
false, -1, IDOperandNo));
ResultOps.push_back(IDOperandNo);
return;
}
Expand Down
4 changes: 2 additions & 2 deletions llvm/utils/TableGen/RegisterInfoEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1709,7 +1709,7 @@ void RegisterInfoEmitter::runTargetDesc(raw_ostream &OS) {
OS << " };\n";
OS << " return ArrayRef(Masks);\n";
} else {
OS << " return std::nullopt;\n";
OS << " return {};\n";
}
OS << "}\n\n";

Expand Down Expand Up @@ -1789,7 +1789,7 @@ void RegisterInfoEmitter::runTargetDesc(raw_ostream &OS) {
OS << " };\n";
OS << " return ArrayRef(Names);\n";
} else {
OS << " return std::nullopt;\n";
OS << " return {};\n";
}
OS << "}\n\n";

Expand Down
8 changes: 4 additions & 4 deletions llvm/utils/TableGen/SubtargetEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2021,11 +2021,11 @@ void SubtargetEmitter::run(raw_ostream &OS) {
if (NumFeatures)
OS << Target << "FeatureKV, ";
else
OS << "std::nullopt, ";
OS << "{}, ";
if (NumProcs)
OS << Target << "SubTypeKV, ";
else
OS << "std::nullopt, ";
OS << "{}, ";
OS << '\n';
OS.indent(22);
OS << Target << "WriteProcResTable, " << Target << "WriteLatencyTable, "
Expand Down Expand Up @@ -2127,11 +2127,11 @@ void SubtargetEmitter::run(raw_ostream &OS) {
if (NumFeatures)
OS << "ArrayRef(" << Target << "FeatureKV, " << NumFeatures << "), ";
else
OS << "std::nullopt, ";
OS << "{}, ";
if (NumProcs)
OS << "ArrayRef(" << Target << "SubTypeKV, " << NumProcs << "), ";
else
OS << "std::nullopt, ";
OS << "{}, ";
OS << '\n';
OS.indent(24);
OS << Target << "WriteProcResTable, " << Target << "WriteLatencyTable, "
Expand Down