Skip to content

Commit

Permalink
Transforms/Utils: llvm::Optional => std::optional
Browse files Browse the repository at this point in the history
  • Loading branch information
MaskRay committed Dec 12, 2022
1 parent a73455a commit c178ed3
Show file tree
Hide file tree
Showing 27 changed files with 146 additions and 138 deletions.
14 changes: 7 additions & 7 deletions llvm/include/llvm/Transforms/Scalar/LoopUnrollPass.h
Expand Up @@ -9,10 +9,10 @@
#ifndef LLVM_TRANSFORMS_SCALAR_LOOPUNROLLPASS_H
#define LLVM_TRANSFORMS_SCALAR_LOOPUNROLLPASS_H

#include "llvm/ADT/Optional.h"
#include "llvm/Analysis/LoopAnalysisManager.h"
#include "llvm/IR/PassManager.h"
#include "llvm/Support/CommandLine.h"
#include <optional>

namespace llvm {

Expand Down Expand Up @@ -59,12 +59,12 @@ class LoopFullUnrollPass : public PassInfoMixin<LoopFullUnrollPass> {
/// additional setters and then pass it to LoopUnrollPass.
///
struct LoopUnrollOptions {
Optional<bool> AllowPartial;
Optional<bool> AllowPeeling;
Optional<bool> AllowRuntime;
Optional<bool> AllowUpperBound;
Optional<bool> AllowProfileBasedPeeling;
Optional<unsigned> FullUnrollMaxCount;
std::optional<bool> AllowPartial;
std::optional<bool> AllowPeeling;
std::optional<bool> AllowRuntime;
std::optional<bool> AllowUpperBound;
std::optional<bool> AllowProfileBasedPeeling;
std::optional<unsigned> FullUnrollMaxCount;
int OptLevel;

/// If false, use a cost model to determine whether unrolling of a loop is
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h
Expand Up @@ -581,7 +581,7 @@ BasicBlock *CreateControlFlowHub(
DomTreeUpdater *DTU, SmallVectorImpl<BasicBlock *> &GuardBlocks,
const SetVector<BasicBlock *> &Predecessors,
const SetVector<BasicBlock *> &Successors, const StringRef Prefix,
Optional<unsigned> MaxControlFlowBooleans = std::nullopt);
std::optional<unsigned> MaxControlFlowBooleans = std::nullopt);

} // end namespace llvm

Expand Down
4 changes: 2 additions & 2 deletions llvm/include/llvm/Transforms/Utils/LoopPeel.h
Expand Up @@ -26,8 +26,8 @@ bool peelLoop(Loop *L, unsigned PeelCount, LoopInfo *LI, ScalarEvolution *SE,
TargetTransformInfo::PeelingPreferences
gatherPeelingPreferences(Loop *L, ScalarEvolution &SE,
const TargetTransformInfo &TTI,
Optional<bool> UserAllowPeeling,
Optional<bool> UserAllowProfileBasedPeeling,
std::optional<bool> UserAllowPeeling,
std::optional<bool> UserAllowProfileBasedPeeling,
bool UnrollingSpecficValues = false);

void computePeelCount(Loop *L, unsigned LoopSize,
Expand Down
14 changes: 7 additions & 7 deletions llvm/include/llvm/Transforms/Utils/LoopUtils.h
Expand Up @@ -226,7 +226,7 @@ SmallVector<Instruction *, 8> findDefsUsedOutsideOfLoop(Loop *L);
/// "llvm.loop.vectorize.scalable.enable") for a loop and use it to construct a
/// ElementCount. If the metadata "llvm.loop.vectorize.width" cannot be found
/// then std::nullopt is returned.
Optional<ElementCount>
std::optional<ElementCount>
getOptionalElementCountLoopAttribute(const Loop *TheLoop);

/// Create a new loop identifier for a loop created from a loop transformation.
Expand All @@ -253,7 +253,7 @@ getOptionalElementCountLoopAttribute(const Loop *TheLoop);
/// @p OrigLoopID: The original identifier can be reused.
/// nullptr : The new loop has no attributes.
/// MDNode* : A new unique loop identifier.
Optional<MDNode *>
std::optional<MDNode *>
makeFollowupLoopID(MDNode *OrigLoopID, ArrayRef<StringRef> FollowupAttrs,
const char *InheritOptionsAttrsPrefix = "",
bool AlwaysNew = false);
Expand Down Expand Up @@ -311,7 +311,7 @@ void addStringMetadataToLoop(Loop *TheLoop, const char *MDString,
/// initialized with weight of loop's latch leading to the exit.
/// Returns 0 when the count is estimated to be 0, or std::nullopt when a
/// meaningful estimate can not be made.
Optional<unsigned>
std::optional<unsigned>
getLoopEstimatedTripCount(Loop *L,
unsigned *EstimatedLoopInvocationWeight = nullptr);

Expand Down Expand Up @@ -541,10 +541,10 @@ struct IVConditionInfo {
/// If the branch condition of the header is partially invariant, return a pair
/// containing the instructions to duplicate and a boolean Constant to update
/// the condition in the loops created for the true or false successors.
Optional<IVConditionInfo> hasPartialIVCondition(const Loop &L,
unsigned MSSAThreshold,
const MemorySSA &MSSA,
AAResults &AA);
std::optional<IVConditionInfo> hasPartialIVCondition(const Loop &L,
unsigned MSSAThreshold,
const MemorySSA &MSSA,
AAResults &AA);

} // end namespace llvm

Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/Transforms/Utils/PredicateInfo.h
Expand Up @@ -103,7 +103,7 @@ class PredicateBase : public ilist_node<PredicateBase> {
}

/// Fetch condition in the form of PredicateConstraint, if possible.
Optional<PredicateConstraint> getConstraint() const;
std::optional<PredicateConstraint> getConstraint() const;

protected:
PredicateBase(PredicateType PT, Value *Op, Value *Condition)
Expand Down
6 changes: 3 additions & 3 deletions llvm/include/llvm/Transforms/Utils/SimplifyLibCalls.h
Expand Up @@ -89,9 +89,9 @@ class FortifiedLibCallSimplifier {
/// parameter. These are used by an implementation to opt-into stricter
/// checking.
bool isFortifiedCallFoldable(CallInst *CI, unsigned ObjSizeOp,
Optional<unsigned> SizeOp = std::nullopt,
Optional<unsigned> StrOp = std::nullopt,
Optional<unsigned> FlagsOp = std::nullopt);
std::optional<unsigned> SizeOp = std::nullopt,
std::optional<unsigned> StrOp = std::nullopt,
std::optional<unsigned> FlagsOp = std::nullopt);
};

/// LibCallSimplifier - This class implements a collection of optimizations
Expand Down
7 changes: 4 additions & 3 deletions llvm/include/llvm/Transforms/Utils/UnrollLoop.h
Expand Up @@ -121,9 +121,10 @@ TargetTransformInfo::UnrollingPreferences gatherUnrollingPreferences(
Loop *L, ScalarEvolution &SE, const TargetTransformInfo &TTI,
BlockFrequencyInfo *BFI, ProfileSummaryInfo *PSI,
llvm::OptimizationRemarkEmitter &ORE, int OptLevel,
Optional<unsigned> UserThreshold, Optional<unsigned> UserCount,
Optional<bool> UserAllowPartial, Optional<bool> UserRuntime,
Optional<bool> UserUpperBound, Optional<unsigned> UserFullUnrollMaxCount);
std::optional<unsigned> UserThreshold, std::optional<unsigned> UserCount,
std::optional<bool> UserAllowPartial, std::optional<bool> UserRuntime,
std::optional<bool> UserUpperBound,
std::optional<unsigned> UserFullUnrollMaxCount);

InstructionCost ApproximateLoopSize(const Loop *L, unsigned &NumCalls,
bool &NotDuplicatable, bool &Convergent, const TargetTransformInfo &TTI,
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Scalar/LoopDistribute.cpp
Expand Up @@ -593,7 +593,7 @@ class InstPartitionContainer {

/// Assign new LoopIDs for the partition's cloned loop.
void setNewLoopID(MDNode *OrigLoopID, InstPartition *Part) {
Optional<MDNode *> PartitionID = makeFollowupLoopID(
std::optional<MDNode *> PartitionID = makeFollowupLoopID(
OrigLoopID,
{LLVMLoopDistributeFollowupAll,
Part->hasDepCycle() ? LLVMLoopDistributeFollowupSequential
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp
Expand Up @@ -368,7 +368,7 @@ tryToUnrollAndJamLoop(Loop *L, DominatorTree &DT, LoopInfo *LI,
// To assign the loop id of the epilogue, assign it before unrolling it so it
// is applied to every inner loop of the epilogue. We later apply the loop ID
// for the jammed inner loop.
Optional<MDNode *> NewInnerEpilogueLoopID = makeFollowupLoopID(
std::optional<MDNode *> NewInnerEpilogueLoopID = makeFollowupLoopID(
OrigOuterLoopID, {LLVMLoopUnrollAndJamFollowupAll,
LLVMLoopUnrollAndJamFollowupRemainderInner});
if (NewInnerEpilogueLoopID)
Expand Down Expand Up @@ -398,14 +398,14 @@ tryToUnrollAndJamLoop(Loop *L, DominatorTree &DT, LoopInfo *LI,

// Assign new loop attributes.
if (EpilogueOuterLoop) {
Optional<MDNode *> NewOuterEpilogueLoopID = makeFollowupLoopID(
std::optional<MDNode *> NewOuterEpilogueLoopID = makeFollowupLoopID(
OrigOuterLoopID, {LLVMLoopUnrollAndJamFollowupAll,
LLVMLoopUnrollAndJamFollowupRemainderOuter});
if (NewOuterEpilogueLoopID)
EpilogueOuterLoop->setLoopID(NewOuterEpilogueLoopID.value());
}

Optional<MDNode *> NewInnerLoopID =
std::optional<MDNode *> NewInnerLoopID =
makeFollowupLoopID(OrigOuterLoopID, {LLVMLoopUnrollAndJamFollowupAll,
LLVMLoopUnrollAndJamFollowupInner});
if (NewInnerLoopID)
Expand All @@ -414,7 +414,7 @@ tryToUnrollAndJamLoop(Loop *L, DominatorTree &DT, LoopInfo *LI,
SubLoop->setLoopID(OrigSubLoopID);

if (UnrollResult == LoopUnrollResult::PartiallyUnrolled) {
Optional<MDNode *> NewOuterLoopID = makeFollowupLoopID(
std::optional<MDNode *> NewOuterLoopID = makeFollowupLoopID(
OrigOuterLoopID,
{LLVMLoopUnrollAndJamFollowupAll, LLVMLoopUnrollAndJamFollowupOuter});
if (NewOuterLoopID) {
Expand Down
82 changes: 43 additions & 39 deletions llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
Expand Up @@ -185,9 +185,10 @@ TargetTransformInfo::UnrollingPreferences llvm::gatherUnrollingPreferences(
Loop *L, ScalarEvolution &SE, const TargetTransformInfo &TTI,
BlockFrequencyInfo *BFI, ProfileSummaryInfo *PSI,
OptimizationRemarkEmitter &ORE, int OptLevel,
Optional<unsigned> UserThreshold, Optional<unsigned> UserCount,
Optional<bool> UserAllowPartial, Optional<bool> UserRuntime,
Optional<bool> UserUpperBound, Optional<unsigned> UserFullUnrollMaxCount) {
std::optional<unsigned> UserThreshold, std::optional<unsigned> UserCount,
std::optional<bool> UserAllowPartial, std::optional<bool> UserRuntime,
std::optional<bool> UserUpperBound,
std::optional<unsigned> UserFullUnrollMaxCount) {
TargetTransformInfo::UnrollingPreferences UP;

// Set up the defaults
Expand Down Expand Up @@ -1119,17 +1120,20 @@ bool llvm::computeUnrollCount(
return ExplicitUnroll;
}

static LoopUnrollResult tryToUnrollLoop(
Loop *L, DominatorTree &DT, LoopInfo *LI, ScalarEvolution &SE,
const TargetTransformInfo &TTI, AssumptionCache &AC,
OptimizationRemarkEmitter &ORE, BlockFrequencyInfo *BFI,
ProfileSummaryInfo *PSI, bool PreserveLCSSA, int OptLevel,
bool OnlyWhenForced, bool ForgetAllSCEV, Optional<unsigned> ProvidedCount,
Optional<unsigned> ProvidedThreshold, Optional<bool> ProvidedAllowPartial,
Optional<bool> ProvidedRuntime, Optional<bool> ProvidedUpperBound,
Optional<bool> ProvidedAllowPeeling,
Optional<bool> ProvidedAllowProfileBasedPeeling,
Optional<unsigned> ProvidedFullUnrollMaxCount) {
static LoopUnrollResult
tryToUnrollLoop(Loop *L, DominatorTree &DT, LoopInfo *LI, ScalarEvolution &SE,
const TargetTransformInfo &TTI, AssumptionCache &AC,
OptimizationRemarkEmitter &ORE, BlockFrequencyInfo *BFI,
ProfileSummaryInfo *PSI, bool PreserveLCSSA, int OptLevel,
bool OnlyWhenForced, bool ForgetAllSCEV,
std::optional<unsigned> ProvidedCount,
std::optional<unsigned> ProvidedThreshold,
std::optional<bool> ProvidedAllowPartial,
std::optional<bool> ProvidedRuntime,
std::optional<bool> ProvidedUpperBound,
std::optional<bool> ProvidedAllowPeeling,
std::optional<bool> ProvidedAllowProfileBasedPeeling,
std::optional<unsigned> ProvidedFullUnrollMaxCount) {
LLVM_DEBUG(dbgs() << "Loop Unroll: F["
<< L->getHeader()->getParent()->getName() << "] Loop %"
<< L->getHeader()->getName() << "\n");
Expand Down Expand Up @@ -1321,15 +1325,15 @@ static LoopUnrollResult tryToUnrollLoop(
return LoopUnrollResult::Unmodified;

if (RemainderLoop) {
Optional<MDNode *> RemainderLoopID =
std::optional<MDNode *> RemainderLoopID =
makeFollowupLoopID(OrigLoopID, {LLVMLoopUnrollFollowupAll,
LLVMLoopUnrollFollowupRemainder});
if (RemainderLoopID)
RemainderLoop->setLoopID(RemainderLoopID.value());
}

if (UnrollResult != LoopUnrollResult::FullyUnrolled) {
Optional<MDNode *> NewLoopID =
std::optional<MDNode *> NewLoopID =
makeFollowupLoopID(OrigLoopID, {LLVMLoopUnrollFollowupAll,
LLVMLoopUnrollFollowupUnrolled});
if (NewLoopID) {
Expand Down Expand Up @@ -1367,25 +1371,25 @@ class LoopUnroll : public LoopPass {
/// Otherwise, forgetAllLoops and rebuild when needed next.
bool ForgetAllSCEV;

Optional<unsigned> ProvidedCount;
Optional<unsigned> ProvidedThreshold;
Optional<bool> ProvidedAllowPartial;
Optional<bool> ProvidedRuntime;
Optional<bool> ProvidedUpperBound;
Optional<bool> ProvidedAllowPeeling;
Optional<bool> ProvidedAllowProfileBasedPeeling;
Optional<unsigned> ProvidedFullUnrollMaxCount;
std::optional<unsigned> ProvidedCount;
std::optional<unsigned> ProvidedThreshold;
std::optional<bool> ProvidedAllowPartial;
std::optional<bool> ProvidedRuntime;
std::optional<bool> ProvidedUpperBound;
std::optional<bool> ProvidedAllowPeeling;
std::optional<bool> ProvidedAllowProfileBasedPeeling;
std::optional<unsigned> ProvidedFullUnrollMaxCount;

LoopUnroll(int OptLevel = 2, bool OnlyWhenForced = false,
bool ForgetAllSCEV = false,
Optional<unsigned> Threshold = std::nullopt,
Optional<unsigned> Count = std::nullopt,
Optional<bool> AllowPartial = std::nullopt,
Optional<bool> Runtime = std::nullopt,
Optional<bool> UpperBound = std::nullopt,
Optional<bool> AllowPeeling = std::nullopt,
Optional<bool> AllowProfileBasedPeeling = std::nullopt,
Optional<unsigned> ProvidedFullUnrollMaxCount = std::nullopt)
std::optional<unsigned> Threshold = std::nullopt,
std::optional<unsigned> Count = std::nullopt,
std::optional<bool> AllowPartial = std::nullopt,
std::optional<bool> Runtime = std::nullopt,
std::optional<bool> UpperBound = std::nullopt,
std::optional<bool> AllowPeeling = std::nullopt,
std::optional<bool> AllowProfileBasedPeeling = std::nullopt,
std::optional<unsigned> ProvidedFullUnrollMaxCount = std::nullopt)
: LoopPass(ID), OptLevel(OptLevel), OnlyWhenForced(OnlyWhenForced),
ForgetAllSCEV(ForgetAllSCEV), ProvidedCount(std::move(Count)),
ProvidedThreshold(Threshold), ProvidedAllowPartial(AllowPartial),
Expand Down Expand Up @@ -1457,12 +1461,12 @@ Pass *llvm::createLoopUnrollPass(int OptLevel, bool OnlyWhenForced,
// callers.
return new LoopUnroll(
OptLevel, OnlyWhenForced, ForgetAllSCEV,
Threshold == -1 ? std::nullopt : Optional<unsigned>(Threshold),
Count == -1 ? std::nullopt : Optional<unsigned>(Count),
AllowPartial == -1 ? std::nullopt : Optional<bool>(AllowPartial),
Runtime == -1 ? std::nullopt : Optional<bool>(Runtime),
UpperBound == -1 ? std::nullopt : Optional<bool>(UpperBound),
AllowPeeling == -1 ? std::nullopt : Optional<bool>(AllowPeeling));
Threshold == -1 ? std::nullopt : std::optional<unsigned>(Threshold),
Count == -1 ? std::nullopt : std::optional<unsigned>(Count),
AllowPartial == -1 ? std::nullopt : std::optional<bool>(AllowPartial),
Runtime == -1 ? std::nullopt : std::optional<bool>(Runtime),
UpperBound == -1 ? std::nullopt : std::optional<bool>(UpperBound),
AllowPeeling == -1 ? std::nullopt : std::optional<bool>(AllowPeeling));
}

Pass *llvm::createSimpleLoopUnrollPass(int OptLevel, bool OnlyWhenForced,
Expand Down Expand Up @@ -1611,7 +1615,7 @@ PreservedAnalyses LoopUnrollPass::run(Function &F,
// Check if the profile summary indicates that the profiled application
// has a huge working set size, in which case we disable peeling to avoid
// bloating it further.
Optional<bool> LocalAllowPeeling = UnrollOpts.AllowPeeling;
std::optional<bool> LocalAllowPeeling = UnrollOpts.AllowPeeling;
if (PSI && PSI->hasHugeWorkingSetSize())
LocalAllowPeeling = false;
std::string LoopName = std::string(L.getName());
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Scalar/NewGVN.cpp
Expand Up @@ -1563,7 +1563,7 @@ NewGVN::performSymbolicPredicateInfoEvaluation(IntrinsicInst *I) const {

LLVM_DEBUG(dbgs() << "Found predicate info from instruction !\n");

const Optional<PredicateConstraint> &Constraint = PI->getConstraint();
const std::optional<PredicateConstraint> &Constraint = PI->getConstraint();
if (!Constraint)
return ExprResult::none();

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Scalar/WarnMissedTransforms.cpp
Expand Up @@ -48,7 +48,7 @@ static void warnAboutLeftoverTransformations(Loop *L,

if (hasVectorizeTransformation(L) == TM_ForcedByUser) {
LLVM_DEBUG(dbgs() << "Leftover vectorization transformation\n");
Optional<ElementCount> VectorizeWidth =
std::optional<ElementCount> VectorizeWidth =
getOptionalElementCountLoopAttribute(L);
std::optional<int> InterleaveCount =
getOptionalIntLoopAttribute(L, "llvm.loop.interleave.count");
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
Expand Up @@ -1903,7 +1903,7 @@ convertToGuardPredicates(SmallVectorImpl<BasicBlock *> &GuardBlocks,
SmallVectorImpl<WeakVH> &DeletionCandidates,
const BBSetVector &Incoming,
const BBSetVector &Outgoing, const StringRef Prefix,
Optional<unsigned> MaxControlFlowBooleans) {
std::optional<unsigned> MaxControlFlowBooleans) {
BBPredicates GuardPredicates;
auto F = Incoming.front()->getParent();

Expand All @@ -1928,7 +1928,7 @@ convertToGuardPredicates(SmallVectorImpl<BasicBlock *> &GuardBlocks,
BasicBlock *llvm::CreateControlFlowHub(
DomTreeUpdater *DTU, SmallVectorImpl<BasicBlock *> &GuardBlocks,
const BBSetVector &Incoming, const BBSetVector &Outgoing,
const StringRef Prefix, Optional<unsigned> MaxControlFlowBooleans) {
const StringRef Prefix, std::optional<unsigned> MaxControlFlowBooleans) {
if (Outgoing.size() < 2)
return Outgoing.front();

Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/Transforms/Utils/BypassSlowDivision.cpp
Expand Up @@ -86,7 +86,7 @@ class FastDivInsertionTask {
QuotRemPair createDivRemPhiNodes(QuotRemWithBB &LHS, QuotRemWithBB &RHS,
BasicBlock *PhiBB);
Value *insertOperandRuntimeCheck(Value *Op1, Value *Op2);
Optional<QuotRemPair> insertFastDivAndRem();
std::optional<QuotRemPair> insertFastDivAndRem();

bool isSignedOp() {
return SlowDivOrRem->getOpcode() == Instruction::SDiv ||
Expand Down Expand Up @@ -160,7 +160,7 @@ Value *FastDivInsertionTask::getReplacement(DivCacheTy &Cache) {

if (CacheI == Cache.end()) {
// If previous instance does not exist, try to insert fast div.
Optional<QuotRemPair> OptResult = insertFastDivAndRem();
std::optional<QuotRemPair> OptResult = insertFastDivAndRem();
// Bail out if insertFastDivAndRem has failed.
if (!OptResult)
return nullptr;
Expand Down Expand Up @@ -349,7 +349,7 @@ Value *FastDivInsertionTask::insertOperandRuntimeCheck(Value *Op1, Value *Op2) {

/// Substitutes the div/rem instruction with code that checks the value of the
/// operands and uses a shorter-faster div/rem instruction when possible.
Optional<QuotRemPair> FastDivInsertionTask::insertFastDivAndRem() {
std::optional<QuotRemPair> FastDivInsertionTask::insertFastDivAndRem() {
Value *Dividend = SlowDivOrRem->getOperand(0);
Value *Divisor = SlowDivOrRem->getOperand(1);

Expand Down

0 comments on commit c178ed3

Please sign in to comment.