Skip to content

Commit 21cd58b

Browse files
committed
[Transforms/InstCombine] llvm::Optional => std::optional
1 parent 1b9ca45 commit 21cd58b

File tree

6 files changed

+27
-30
lines changed

6 files changed

+27
-30
lines changed

llvm/include/llvm/Transforms/InstCombine/InstCombiner.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ class LLVM_LIBRARY_VISIBILITY InstCombiner {
208208
return ConstantExpr::getSub(C, ConstantInt::get(C->getType(), 1));
209209
}
210210

211-
llvm::Optional<std::pair<
211+
std::optional<std::pair<
212212
CmpInst::Predicate,
213213
Constant *>> static getFlippedStrictnessPredicateAndConstant(CmpInst::
214214
Predicate

llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -233,13 +233,9 @@ static bool decomposeBitTestICmp(Value *LHS, Value *RHS, CmpInst::Predicate &Pre
233233
/// the right hand side as a pair.
234234
/// LHS and RHS are the left hand side and the right hand side ICmps and PredL
235235
/// and PredR are their predicates, respectively.
236-
static
237-
Optional<std::pair<unsigned, unsigned>>
238-
getMaskedTypeForICmpPair(Value *&A, Value *&B, Value *&C,
239-
Value *&D, Value *&E, ICmpInst *LHS,
240-
ICmpInst *RHS,
241-
ICmpInst::Predicate &PredL,
242-
ICmpInst::Predicate &PredR) {
236+
static std::optional<std::pair<unsigned, unsigned>> getMaskedTypeForICmpPair(
237+
Value *&A, Value *&B, Value *&C, Value *&D, Value *&E, ICmpInst *LHS,
238+
ICmpInst *RHS, ICmpInst::Predicate &PredL, ICmpInst::Predicate &PredR) {
243239
// Don't allow pointers. Splat vectors are fine.
244240
if (!LHS->getOperand(0)->getType()->isIntOrIntVectorTy() ||
245241
!RHS->getOperand(0)->getType()->isIntOrIntVectorTy())
@@ -358,7 +354,8 @@ getMaskedTypeForICmpPair(Value *&A, Value *&B, Value *&C,
358354

359355
unsigned LeftType = getMaskedICmpType(A, B, C, PredL);
360356
unsigned RightType = getMaskedICmpType(A, D, E, PredR);
361-
return Optional<std::pair<unsigned, unsigned>>(std::make_pair(LeftType, RightType));
357+
return std::optional<std::pair<unsigned, unsigned>>(
358+
std::make_pair(LeftType, RightType));
362359
}
363360

364361
/// Try to fold (icmp(A & B) ==/!= C) &/| (icmp(A & D) ==/!= E) into a single
@@ -526,7 +523,7 @@ static Value *foldLogOpOfMaskedICmps(ICmpInst *LHS, ICmpInst *RHS, bool IsAnd,
526523
InstCombiner::BuilderTy &Builder) {
527524
Value *A = nullptr, *B = nullptr, *C = nullptr, *D = nullptr, *E = nullptr;
528525
ICmpInst::Predicate PredL = LHS->getPredicate(), PredR = RHS->getPredicate();
529-
Optional<std::pair<unsigned, unsigned>> MaskPair =
526+
std::optional<std::pair<unsigned, unsigned>> MaskPair =
530527
getMaskedTypeForICmpPair(A, B, C, D, E, LHS, RHS, PredL, PredR);
531528
if (!MaskPair)
532529
return nullptr;
@@ -1016,7 +1013,7 @@ struct IntPart {
10161013
};
10171014

10181015
/// Match an extraction of bits from an integer.
1019-
static Optional<IntPart> matchIntPart(Value *V) {
1016+
static std::optional<IntPart> matchIntPart(Value *V) {
10201017
Value *X;
10211018
if (!match(V, m_OneUse(m_Trunc(m_Value(X)))))
10221019
return std::nullopt;
@@ -1056,10 +1053,10 @@ Value *InstCombinerImpl::foldEqOfParts(ICmpInst *Cmp0, ICmpInst *Cmp1,
10561053
if (Cmp0->getPredicate() != Pred || Cmp1->getPredicate() != Pred)
10571054
return nullptr;
10581055

1059-
Optional<IntPart> L0 = matchIntPart(Cmp0->getOperand(0));
1060-
Optional<IntPart> R0 = matchIntPart(Cmp0->getOperand(1));
1061-
Optional<IntPart> L1 = matchIntPart(Cmp1->getOperand(0));
1062-
Optional<IntPart> R1 = matchIntPart(Cmp1->getOperand(1));
1056+
std::optional<IntPart> L0 = matchIntPart(Cmp0->getOperand(0));
1057+
std::optional<IntPart> R0 = matchIntPart(Cmp0->getOperand(1));
1058+
std::optional<IntPart> L1 = matchIntPart(Cmp1->getOperand(0));
1059+
std::optional<IntPart> R1 = matchIntPart(Cmp1->getOperand(1));
10631060
if (!L0 || !R0 || !L1 || !R1)
10641061
return nullptr;
10651062

llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5850,7 +5850,7 @@ static Instruction *foldICmpUsingBoolRange(ICmpInst &I,
58505850
return nullptr;
58515851
}
58525852

5853-
llvm::Optional<std::pair<CmpInst::Predicate, Constant *>>
5853+
std::optional<std::pair<CmpInst::Predicate, Constant *>>
58545854
InstCombiner::getFlippedStrictnessPredicateAndConstant(CmpInst::Predicate Pred,
58555855
Constant *C) {
58565856
assert(ICmpInst::isRelational(Pred) && ICmpInst::isIntPredicate(Pred) &&

llvm/lib/Transforms/InstCombine/InstCombineInternal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ class Negator final {
801801

802802
/// Recurse depth-first and attempt to sink the negation.
803803
/// FIXME: use worklist?
804-
[[nodiscard]] Optional<Result> run(Value *Root);
804+
[[nodiscard]] std::optional<Result> run(Value *Root);
805805

806806
Negator(const Negator &) = delete;
807807
Negator(Negator &&) = delete;

llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ std::array<Value *, 2> Negator::getSortedOperandsOfBinOp(Instruction *I) {
514514
return NegatedV;
515515
}
516516

517-
[[nodiscard]] Optional<Negator::Result> Negator::run(Value *Root) {
517+
[[nodiscard]] std::optional<Negator::Result> Negator::run(Value *Root) {
518518
Value *Negated = negate(Root, /*Depth=*/0);
519519
if (!Negated) {
520520
// We must cleanup newly-inserted instructions, to avoid any potential
@@ -537,7 +537,7 @@ std::array<Value *, 2> Negator::getSortedOperandsOfBinOp(Instruction *I) {
537537

538538
Negator N(Root->getContext(), IC.getDataLayout(), IC.getAssumptionCache(),
539539
IC.getDominatorTree(), LHSIsZero);
540-
Optional<Result> Res = N.run(Root);
540+
std::optional<Result> Res = N.run(Root);
541541
if (!Res) { // Negation failed.
542542
LLVM_DEBUG(dbgs() << "Negator: failed to sink negation into " << *Root
543543
<< "\n");

llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,7 @@ Instruction *InstCombinerImpl::foldAggregateConstructionIntoAggregateReuse(
875875

876876
// Try to find a value of each element of an aggregate.
877877
// FIXME: deal with more complex, not one-dimensional, aggregate types
878-
SmallVector<Optional<Instruction *>, 2> AggElts(NumAggElts, NotFound);
878+
SmallVector<std::optional<Instruction *>, 2> AggElts(NumAggElts, NotFound);
879879

880880
// Do we know values for each element of the aggregate?
881881
auto KnowAllElts = [&AggElts]() {
@@ -908,7 +908,7 @@ Instruction *InstCombinerImpl::foldAggregateConstructionIntoAggregateReuse(
908908
// Now, we may have already previously recorded the value for this element
909909
// of an aggregate. If we did, that means the CurrIVI will later be
910910
// overwritten with the already-recorded value. But if not, let's record it!
911-
Optional<Instruction *> &Elt = AggElts[Indices.front()];
911+
std::optional<Instruction *> &Elt = AggElts[Indices.front()];
912912
Elt = Elt.value_or(InsertedValue);
913913

914914
// FIXME: should we handle chain-terminating undef base operand?
@@ -938,7 +938,7 @@ Instruction *InstCombinerImpl::foldAggregateConstructionIntoAggregateReuse(
938938
/// or different elements had different source aggregates.
939939
FoundMismatch
940940
};
941-
auto Describe = [](Optional<Value *> SourceAggregate) {
941+
auto Describe = [](std::optional<Value *> SourceAggregate) {
942942
if (SourceAggregate == NotFound)
943943
return AggregateDescription::NotFound;
944944
if (*SourceAggregate == FoundMismatch)
@@ -952,8 +952,8 @@ Instruction *InstCombinerImpl::foldAggregateConstructionIntoAggregateReuse(
952952
// If found, return the source aggregate from which the extraction was.
953953
// If \p PredBB is provided, does PHI translation of an \p Elt first.
954954
auto FindSourceAggregate =
955-
[&](Instruction *Elt, unsigned EltIdx, Optional<BasicBlock *> UseBB,
956-
Optional<BasicBlock *> PredBB) -> Optional<Value *> {
955+
[&](Instruction *Elt, unsigned EltIdx, std::optional<BasicBlock *> UseBB,
956+
std::optional<BasicBlock *> PredBB) -> std::optional<Value *> {
957957
// For now(?), only deal with, at most, a single level of PHI indirection.
958958
if (UseBB && PredBB)
959959
Elt = dyn_cast<Instruction>(Elt->DoPHITranslation(*UseBB, *PredBB));
@@ -980,9 +980,9 @@ Instruction *InstCombinerImpl::foldAggregateConstructionIntoAggregateReuse(
980980
// see if we can find appropriate source aggregate for each of the elements,
981981
// and see it's the same aggregate for each element. If so, return it.
982982
auto FindCommonSourceAggregate =
983-
[&](Optional<BasicBlock *> UseBB,
984-
Optional<BasicBlock *> PredBB) -> Optional<Value *> {
985-
Optional<Value *> SourceAggregate;
983+
[&](std::optional<BasicBlock *> UseBB,
984+
std::optional<BasicBlock *> PredBB) -> std::optional<Value *> {
985+
std::optional<Value *> SourceAggregate;
986986

987987
for (auto I : enumerate(AggElts)) {
988988
assert(Describe(SourceAggregate) != AggregateDescription::FoundMismatch &&
@@ -994,7 +994,7 @@ Instruction *InstCombinerImpl::foldAggregateConstructionIntoAggregateReuse(
994994
// For this element, is there a plausible source aggregate?
995995
// FIXME: we could special-case undef element, IFF we know that in the
996996
// source aggregate said element isn't poison.
997-
Optional<Value *> SourceAggregateForElement =
997+
std::optional<Value *> SourceAggregateForElement =
998998
FindSourceAggregate(*I.value(), I.index(), UseBB, PredBB);
999999

10001000
// Okay, what have we found? Does that correlate with previous findings?
@@ -1028,7 +1028,7 @@ Instruction *InstCombinerImpl::foldAggregateConstructionIntoAggregateReuse(
10281028
return *SourceAggregate;
10291029
};
10301030

1031-
Optional<Value *> SourceAggregate;
1031+
std::optional<Value *> SourceAggregate;
10321032

10331033
// Can we find the source aggregate without looking at predecessors?
10341034
SourceAggregate = FindCommonSourceAggregate(/*UseBB=*/std::nullopt,
@@ -1049,7 +1049,7 @@ Instruction *InstCombinerImpl::foldAggregateConstructionIntoAggregateReuse(
10491049
// they all should be defined in the same basic block.
10501050
BasicBlock *UseBB = nullptr;
10511051

1052-
for (const Optional<Instruction *> &I : AggElts) {
1052+
for (const std::optional<Instruction *> &I : AggElts) {
10531053
BasicBlock *BB = (*I)->getParent();
10541054
// If it's the first instruction we've encountered, record the basic block.
10551055
if (!UseBB) {

0 commit comments

Comments
 (0)