From 343de6856e16b58bcbd16d479fc633f54e22fadc Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Fri, 2 Dec 2022 21:11:37 -0800 Subject: [PATCH] [Transforms] Use std::nullopt instead of None (NFC) This patch mechanically replaces None with std::nullopt where the compiler would warn if None were deprecated. The intent is to reduce the amount of manual work required in migrating from Optional to std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716 --- llvm/include/llvm/Transforms/IPO/Attributor.h | 6 +- llvm/include/llvm/Transforms/Scalar/GVN.h | 10 +- .../llvm/Transforms/Scalar/LoopPassManager.h | 2 +- .../llvm/Transforms/Utils/BasicBlockUtils.h | 9 +- .../llvm/Transforms/Utils/SimplifyLibCalls.h | 6 +- llvm/lib/Transforms/Coroutines/CoroElide.cpp | 2 +- llvm/lib/Transforms/Coroutines/CoroFrame.cpp | 12 +- llvm/lib/Transforms/IPO/ArgumentPromotion.cpp | 2 +- llvm/lib/Transforms/IPO/Attributor.cpp | 6 +- llvm/lib/Transforms/IPO/AttributorAttributes.cpp | 18 +-- llvm/lib/Transforms/IPO/GlobalOpt.cpp | 2 +- llvm/lib/Transforms/IPO/IROutliner.cpp | 9 +- llvm/lib/Transforms/IPO/OpenMPOpt.cpp | 8 +- llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp | 4 +- .../Transforms/InstCombine/InstCombineAndOrXor.cpp | 12 +- .../Transforms/InstCombine/InstCombineCalls.cpp | 2 +- .../Transforms/InstCombine/InstCombineCompares.cpp | 8 +- .../Transforms/InstCombine/InstCombineNegator.cpp | 2 +- .../InstCombine/InstCombineVectorOps.cpp | 5 +- .../InstCombine/InstructionCombining.cpp | 16 +- .../Instrumentation/AddressSanitizer.cpp | 5 +- .../Instrumentation/DataFlowSanitizer.cpp | 4 +- .../Instrumentation/HWAddressSanitizer.cpp | 5 +- .../lib/Transforms/Instrumentation/MemProfiler.cpp | 24 +-- .../Transforms/Instrumentation/MemorySanitizer.cpp | 2 +- .../Instrumentation/SanitizerCoverage.cpp | 2 +- llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp | 3 +- llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp | 2 +- .../Transforms/Scalar/AlignmentFromAssumptions.cpp | 2 +- .../lib/Transforms/Scalar/DeadStoreElimination.cpp | 34 ++-- llvm/lib/Transforms/Scalar/Float2Int.cpp | 2 +- llvm/lib/Transforms/Scalar/GVN.cpp | 18 ++- llvm/lib/Transforms/Scalar/GVNSink.cpp | 16 +- .../Scalar/InductiveRangeCheckElimination.cpp | 64 ++++---- llvm/lib/Transforms/Scalar/LoopFuse.cpp | 8 +- llvm/lib/Transforms/Scalar/LoopPredication.cpp | 48 +++--- llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp | 14 +- .../lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp | 8 +- llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp | 85 +++++----- llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp | 2 +- llvm/lib/Transforms/Scalar/MergeICmps.cpp | 22 +-- .../Transforms/Scalar/RewriteStatepointsForGC.cpp | 2 +- llvm/lib/Transforms/Scalar/Scalarizer.cpp | 4 +- llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp | 4 +- llvm/lib/Transforms/Utils/BasicBlockUtils.cpp | 4 +- llvm/lib/Transforms/Utils/BypassSlowDivision.cpp | 8 +- llvm/lib/Transforms/Utils/CodeExtractor.cpp | 3 +- llvm/lib/Transforms/Utils/CodeMoverUtils.cpp | 10 +- llvm/lib/Transforms/Utils/Debugify.cpp | 3 +- llvm/lib/Transforms/Utils/InlineFunction.cpp | 5 +- llvm/lib/Transforms/Utils/Local.cpp | 8 +- llvm/lib/Transforms/Utils/LoopPeel.cpp | 4 +- llvm/lib/Transforms/Utils/LoopUnroll.cpp | 8 +- llvm/lib/Transforms/Utils/LoopUtils.cpp | 12 +- llvm/lib/Transforms/Utils/MemoryOpRemark.cpp | 8 +- llvm/lib/Transforms/Utils/PredicateInfo.cpp | 6 +- llvm/lib/Transforms/Utils/SimplifyCFG.cpp | 8 +- llvm/lib/Transforms/Utils/SimplifyIndVar.cpp | 5 +- llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp | 12 +- llvm/lib/Transforms/Utils/ValueMapper.cpp | 11 +- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp | 20 +-- llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp | 179 +++++++++++---------- llvm/lib/Transforms/Vectorize/VPlanSLP.cpp | 2 +- 63 files changed, 429 insertions(+), 408 deletions(-) diff --git a/llvm/include/llvm/Transforms/IPO/Attributor.h b/llvm/include/llvm/Transforms/IPO/Attributor.h index 04e560a..11c3cdf 100644 --- a/llvm/include/llvm/Transforms/IPO/Attributor.h +++ b/llvm/include/llvm/Transforms/IPO/Attributor.h @@ -1348,7 +1348,7 @@ struct AttributorConfig { DenseSet *Allowed = nullptr; /// Maximum number of iterations to run until fixpoint. - std::optional MaxFixpointIterations = None; + std::optional MaxFixpointIterations = std::nullopt; /// A callback function that returns an ORE object from a Function pointer. ///{ @@ -4392,7 +4392,7 @@ struct AAValueConstantRange AA::getWithType(*ConstantInt::get(Ty->getContext(), *C), *Ty)); } if (RangeV.isEmptySet()) - return llvm::None; + return std::nullopt; return nullptr; } @@ -4647,7 +4647,7 @@ struct AAPotentialConstantValues if (getAssumedSet().size() == 0) { if (undefIsContained()) return UndefValue::get(getAssociatedValue().getType()); - return llvm::None; + return std::nullopt; } return nullptr; diff --git a/llvm/include/llvm/Transforms/Scalar/GVN.h b/llvm/include/llvm/Transforms/Scalar/GVN.h index 85d0cde..888a537 100644 --- a/llvm/include/llvm/Transforms/Scalar/GVN.h +++ b/llvm/include/llvm/Transforms/Scalar/GVN.h @@ -72,11 +72,11 @@ class GVNLegacyPass; /// Intended use is to create a default object, modify parameters with /// additional setters and then pass it to GVN. struct GVNOptions { - std::optional AllowPRE = None; - std::optional AllowLoadPRE = None; - std::optional AllowLoadInLoopPRE = None; - std::optional AllowLoadPRESplitBackedge = None; - std::optional AllowMemDep = None; + std::optional AllowPRE = std::nullopt; + std::optional AllowLoadPRE = std::nullopt; + std::optional AllowLoadInLoopPRE = std::nullopt; + std::optional AllowLoadPRESplitBackedge = std::nullopt; + std::optional AllowMemDep = std::nullopt; GVNOptions() = default; diff --git a/llvm/include/llvm/Transforms/Scalar/LoopPassManager.h b/llvm/include/llvm/Transforms/Scalar/LoopPassManager.h index 987b6fa..7dd78de 100644 --- a/llvm/include/llvm/Transforms/Scalar/LoopPassManager.h +++ b/llvm/include/llvm/Transforms/Scalar/LoopPassManager.h @@ -403,7 +403,7 @@ Optional LoopPassManager::runSinglePass( // Check the PassInstrumentation's BeforePass callbacks before running the // pass, skip its execution completely if asked to (callback returns false). if (!PI.runBeforePass(*Pass, L)) - return None; + return std::nullopt; PreservedAnalyses PA = Pass->run(IR, AM, AR, U); diff --git a/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h b/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h index fc6b0cb..8215fe4 100644 --- a/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h +++ b/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h @@ -574,12 +574,11 @@ bool SplitIndirectBrCriticalEdges(Function &F, bool IgnoreBlocksWithoutPHI, /// for the caller to accomplish, since each specific use of this function /// may have additional information which simplifies this fixup. For example, /// see restoreSSA() in the UnifyLoopExits pass. -BasicBlock *CreateControlFlowHub(DomTreeUpdater *DTU, - SmallVectorImpl &GuardBlocks, +BasicBlock *CreateControlFlowHub( + DomTreeUpdater *DTU, SmallVectorImpl &GuardBlocks, const SetVector &Predecessors, - const SetVector &Successors, - const StringRef Prefix, - Optional MaxControlFlowBooleans = None); + const SetVector &Successors, const StringRef Prefix, + Optional MaxControlFlowBooleans = std::nullopt); } // end namespace llvm diff --git a/llvm/include/llvm/Transforms/Utils/SimplifyLibCalls.h b/llvm/include/llvm/Transforms/Utils/SimplifyLibCalls.h index a9e26c0..9783396 100644 --- a/llvm/include/llvm/Transforms/Utils/SimplifyLibCalls.h +++ b/llvm/include/llvm/Transforms/Utils/SimplifyLibCalls.h @@ -89,9 +89,9 @@ private: /// parameter. These are used by an implementation to opt-into stricter /// checking. bool isFortifiedCallFoldable(CallInst *CI, unsigned ObjSizeOp, - Optional SizeOp = None, - Optional StrOp = None, - Optional FlagsOp = None); + Optional SizeOp = std::nullopt, + Optional StrOp = std::nullopt, + Optional FlagsOp = std::nullopt); }; /// LibCallSimplifier - This class implements a collection of optimizations diff --git a/llvm/lib/Transforms/Coroutines/CoroElide.cpp b/llvm/lib/Transforms/Coroutines/CoroElide.cpp index fcb3b3e..f032c56 100644 --- a/llvm/lib/Transforms/Coroutines/CoroElide.cpp +++ b/llvm/lib/Transforms/Coroutines/CoroElide.cpp @@ -107,7 +107,7 @@ getFrameLayout(Function *Resume) { // Pull information from the function attributes. auto Size = Resume->getParamDereferenceableBytes(0); if (!Size) - return None; + return std::nullopt; return std::make_pair(Size, Resume->getParamAlign(0).valueOrOne()); } diff --git a/llvm/lib/Transforms/Coroutines/CoroFrame.cpp b/llvm/lib/Transforms/Coroutines/CoroFrame.cpp index fda637f..8cd0a91 100644 --- a/llvm/lib/Transforms/Coroutines/CoroFrame.cpp +++ b/llvm/lib/Transforms/Coroutines/CoroFrame.cpp @@ -892,7 +892,7 @@ static DIType *solveDIType(DIBuilder &Builder, Type *Ty, RetType = Builder.createPointerType(nullptr, Layout.getTypeSizeInBits(Ty), Layout.getABITypeAlignment(Ty) * CHAR_BIT, - /*DWARFAddressSpace=*/None, Name); + /*DWARFAddressSpace=*/std::nullopt, Name); } else if (Ty->isStructTy()) { auto *DIStruct = Builder.createStructType( Scope, Name, Scope->getFile(), LineNum, Layout.getTypeSizeInBits(Ty), @@ -1149,8 +1149,8 @@ static StructType *buildFrameType(Function &F, coro::Shape &Shape, // Add header fields for the resume and destroy functions. // We can rely on these being perfectly packed. - (void)B.addField(FnPtrTy, None, /*header*/ true); - (void)B.addField(FnPtrTy, None, /*header*/ true); + (void)B.addField(FnPtrTy, std::nullopt, /*header*/ true); + (void)B.addField(FnPtrTy, std::nullopt, /*header*/ true); // PromiseAlloca field needs to be explicitly added here because it's // a header field with a fixed offset based on its alignment. Hence it @@ -1164,7 +1164,7 @@ static StructType *buildFrameType(Function &F, coro::Shape &Shape, unsigned IndexBits = std::max(1U, Log2_64_Ceil(Shape.CoroSuspends.size())); Type *IndexType = Type::getIntNTy(C, IndexBits); - SwitchIndexFieldId = B.addField(IndexType, None); + SwitchIndexFieldId = B.addField(IndexType, std::nullopt); } else { assert(PromiseAlloca == nullptr && "lowering doesn't support promises"); } @@ -1189,8 +1189,8 @@ static StructType *buildFrameType(Function &F, coro::Shape &Shape, if (const Argument *A = dyn_cast(S.first)) if (A->hasByValAttr()) FieldType = A->getParamByValType(); - FieldIDType Id = - B.addField(FieldType, None, false /*header*/, true /*IsSpillOfValue*/); + FieldIDType Id = B.addField(FieldType, std::nullopt, false /*header*/, + true /*IsSpillOfValue*/); FrameData.setFieldIndex(S.first, Id); } diff --git a/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp b/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp index 8c77b69..467ab7f 100644 --- a/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp +++ b/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp @@ -489,7 +489,7 @@ static bool findArgParts(Argument *Arg, const DataLayout &DL, AAResults &AAR, Ptr = Ptr->stripAndAccumulateConstantOffsets(DL, Offset, /* AllowNonInbounds */ true); if (Ptr != Arg) - return None; + return std::nullopt; if (Offset.getSignificantBits() >= 64) return false; diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp index 2699852..227ccc9 100644 --- a/llvm/lib/Transforms/IPO/Attributor.cpp +++ b/llvm/lib/Transforms/IPO/Attributor.cpp @@ -1079,7 +1079,7 @@ Attributor::getAssumedConstant(const IRPosition &IRP, for (auto &CB : SimplificationCallbacks.lookup(IRP)) { Optional SimplifiedV = CB(IRP, &AA, UsedAssumedInformation); if (!SimplifiedV) - return llvm::None; + return std::nullopt; if (isa_and_nonnull(*SimplifiedV)) return cast(*SimplifiedV); return nullptr; @@ -1091,7 +1091,7 @@ Attributor::getAssumedConstant(const IRPosition &IRP, AA::ValueScope::Interprocedural, UsedAssumedInformation)) { if (Values.empty()) - return llvm::None; + return std::nullopt; if (auto *C = dyn_cast_or_null( AAPotentialValues::getSingleValue(*this, AA, IRP, Values))) return C; @@ -1113,7 +1113,7 @@ Optional Attributor::getAssumedSimplified(const IRPosition &IRP, if (!getAssumedSimplifiedValues(IRP, AA, Values, S, UsedAssumedInformation)) return &IRP.getAssociatedValue(); if (Values.empty()) - return llvm::None; + return std::nullopt; if (AA) if (Value *V = AAPotentialValues::getSingleValue(*this, *AA, IRP, Values)) return V; diff --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp index 875f7e2..1715460 100644 --- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp +++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp @@ -2861,7 +2861,7 @@ private: // If it is known (which we tested above) but it doesn't have a value, // then we can assume `undef` and hence the instruction is UB. KnownUBInsts.insert(I); - return llvm::None; + return std::nullopt; } if (!*SimplifiedV) return nullptr; @@ -2869,7 +2869,7 @@ private: } if (isa(V)) { KnownUBInsts.insert(I); - return llvm::None; + return std::nullopt; } return V; } @@ -5534,7 +5534,7 @@ struct AAValueSimplifyImpl : AAValueSimplify { Optional COpt = AA.getAssumedConstant(A); if (!COpt) { - SimplifiedAssociatedValue = llvm::None; + SimplifiedAssociatedValue = std::nullopt; A.recordDependence(AA, *this, DepClassTy::OPTIONAL); return true; } @@ -6091,7 +6091,7 @@ struct AAHeapToStackFunction final : public AAHeapToStack { if (!isa(InitVal)) { IRBuilder<> Builder(Alloca->getNextNode()); // TODO: Use alignment above if align!=1 - Builder.CreateMemSet(Alloca, InitVal, Size, None); + Builder.CreateMemSet(Alloca, InitVal, Size, std::nullopt); } HasChanged = ChangeStatus::CHANGED; } @@ -6108,7 +6108,7 @@ struct AAHeapToStackFunction final : public AAHeapToStack { return APInt(64, 0); if (auto *CI = dyn_cast_or_null(SimpleV.value())) return CI->getValue(); - return llvm::None; + return std::nullopt; } Optional getSize(Attributor &A, const AbstractAttribute &AA, @@ -6439,7 +6439,7 @@ ChangeStatus AAHeapToStackFunction::updateImpl(Attributor &A) { namespace { struct AAPrivatizablePtrImpl : public AAPrivatizablePtr { AAPrivatizablePtrImpl(const IRPosition &IRP, Attributor &A) - : AAPrivatizablePtr(IRP, A), PrivatizableType(llvm::None) {} + : AAPrivatizablePtr(IRP, A), PrivatizableType(std::nullopt) {} ChangeStatus indicatePessimisticFixpoint() override { AAPrivatizablePtr::indicatePessimisticFixpoint(); @@ -9630,7 +9630,7 @@ private: if (Unreachable.count(&Fn)) return false; - return llvm::None; + return std::nullopt; } /// Set of functions that we know for sure is reachable. @@ -9909,7 +9909,7 @@ askForAssumedConstant(Attributor &A, const AbstractAttribute &QueryingAA, if (!COpt.has_value()) { A.recordDependence(AA, QueryingAA, DepClassTy::OPTIONAL); - return llvm::None; + return std::nullopt; } if (auto *C = COpt.value()) { A.recordDependence(AA, QueryingAA, DepClassTy::OPTIONAL); @@ -9972,7 +9972,7 @@ struct AAPotentialValuesImpl : AAPotentialValues { return &IRP.getAssociatedValue(); Optional C = askForAssumedConstant(A, AA, IRP, Ty); if (!C) - return llvm::None; + return std::nullopt; if (C.value()) if (auto *CC = AA::getWithType(**C, Ty)) return CC; diff --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp index 7681f46..80b9f08 100644 --- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp +++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp @@ -883,7 +883,7 @@ OptimizeGlobalAddressOfAllocation(GlobalVariable *GV, CallInst *CI, if (!isa(InitVal)) { IRBuilder<> Builder(CI->getNextNode()); // TODO: Use alignment above if align!=1 - Builder.CreateMemSet(NewGV, InitVal, AllocSize, None); + Builder.CreateMemSet(NewGV, InitVal, AllocSize, std::nullopt); } // Update users of the allocation to use the new global instead. diff --git a/llvm/lib/Transforms/IPO/IROutliner.cpp b/llvm/lib/Transforms/IPO/IROutliner.cpp index 9f89f32..1b1d864 100644 --- a/llvm/lib/Transforms/IPO/IROutliner.cpp +++ b/llvm/lib/Transforms/IPO/IROutliner.cpp @@ -469,7 +469,7 @@ constantMatches(Value *V, unsigned GVN, // See if we have a constants Constant *CST = dyn_cast(V); if (!CST) - return None; + return std::nullopt; // Holds a mapping from a global value number to a Constant. DenseMap::iterator GVNToConstantIt; @@ -684,7 +684,8 @@ Function *IROutliner::createFunction(Module &M, OutlinableGroup &Group, Unit /* Context */, F->getName(), MangledNameStream.str(), Unit /* File */, 0 /* Line 0 is reserved for compiler-generated code. */, - DB.createSubroutineType(DB.getOrCreateTypeArray(None)), /* void type */ + DB.createSubroutineType( + DB.getOrCreateTypeArray(std::nullopt)), /* void type */ 0, /* Line 0 is reserved for compiler-generated code. */ DINode::DIFlags::FlagArtificial /* Compiler-generated code. */, /* Outlined code is optimized code by definition. */ @@ -1193,7 +1194,7 @@ static Optional getGVNForPHINode(OutlinableRegion &Region, Optional OGVN = Cand.getGVN(Incoming); if (!OGVN && Blocks.contains(IncomingBlock)) { Region.IgnoreRegion = true; - return None; + return std::nullopt; } // If the incoming block isn't in the region, we don't have to worry about @@ -2013,7 +2014,7 @@ Optional findDuplicateOutputBlock( MatchingNum++; } - return None; + return std::nullopt; } /// Remove empty output blocks from the outlined region. diff --git a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp index 571ce33..a3af1fa 100644 --- a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp +++ b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp @@ -2342,7 +2342,7 @@ struct AAICVTracker : public StateWrapper { virtual Optional getReplacementValue(InternalControlVar ICV, const Instruction *I, Attributor &A) const { - return None; + return std::nullopt; } /// Return an assumed unique ICV value if a single candidate is found. If @@ -2447,7 +2447,7 @@ struct AAICVTrackerFunction : public AAICVTracker { const auto *CB = dyn_cast(&I); if (!CB || CB->hasFnAttr("no_openmp") || CB->hasFnAttr("no_openmp_routines")) - return None; + return std::nullopt; auto &OMPInfoCache = static_cast(A.getInfoCache()); auto &GetterRFI = OMPInfoCache.RFIs[OMPInfoCache.ICVs[ICV].Getter]; @@ -2458,7 +2458,7 @@ struct AAICVTrackerFunction : public AAICVTracker { if (CalledFunction == nullptr) return nullptr; if (CalledFunction == GetterRFI.Declaration) - return None; + return std::nullopt; if (CalledFunction == SetterRFI.Declaration) { if (ICVReplacementValuesMap[ICV].count(&I)) return ICVReplacementValuesMap[ICV].lookup(&I); @@ -2487,7 +2487,7 @@ struct AAICVTrackerFunction : public AAICVTracker { // We don't check unique value for a function, so return None. Optional getUniqueReplacementValue(InternalControlVar ICV) const override { - return None; + return std::nullopt; } /// Return the value with which \p I can be replaced for specific \p ICV. diff --git a/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp b/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp index 2e838de..9b7af3b 100644 --- a/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp +++ b/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp @@ -814,8 +814,8 @@ void updatePublicTypeTestCalls(Module &M, for (Use &U : make_early_inc_range(PublicTypeTestFunc->uses())) { auto *CI = cast(U.getUser()); auto *NewCI = CallInst::Create( - TypeTestFunc, {CI->getArgOperand(0), CI->getArgOperand(1)}, None, "", - CI); + TypeTestFunc, {CI->getArgOperand(0), CI->getArgOperand(1)}, + std::nullopt, "", CI); CI->replaceAllUsesWith(NewCI); CI->eraseFromParent(); } diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp index c3dabc2..39b4af5 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp @@ -243,7 +243,7 @@ getMaskedTypeForICmpPair(Value *&A, Value *&B, Value *&C, // Don't allow pointers. Splat vectors are fine. if (!LHS->getOperand(0)->getType()->isIntOrIntVectorTy() || !RHS->getOperand(0)->getType()->isIntOrIntVectorTy()) - return None; + return std::nullopt; // Here comes the tricky part: // LHS might be of the form L11 & L12 == X, X == L21 & L22, @@ -274,7 +274,7 @@ getMaskedTypeForICmpPair(Value *&A, Value *&B, Value *&C, // Bail if LHS was a icmp that can't be decomposed into an equality. if (!ICmpInst::isEquality(PredL)) - return None; + return std::nullopt; Value *R1 = RHS->getOperand(0); Value *R2 = RHS->getOperand(1); @@ -288,7 +288,7 @@ getMaskedTypeForICmpPair(Value *&A, Value *&B, Value *&C, A = R12; D = R11; } else { - return None; + return std::nullopt; } E = R2; R1 = nullptr; @@ -316,7 +316,7 @@ getMaskedTypeForICmpPair(Value *&A, Value *&B, Value *&C, // Bail if RHS was a icmp that can't be decomposed into an equality. if (!ICmpInst::isEquality(PredR)) - return None; + return std::nullopt; // Look for ANDs on the right side of the RHS icmp. if (!Ok) { @@ -336,7 +336,7 @@ getMaskedTypeForICmpPair(Value *&A, Value *&B, Value *&C, E = R1; Ok = true; } else { - return None; + return std::nullopt; } assert(Ok && "Failed to find AND on the right side of the RHS icmp."); @@ -1019,7 +1019,7 @@ struct IntPart { static Optional matchIntPart(Value *V) { Value *X; if (!match(V, m_OneUse(m_Trunc(m_Value(X))))) - return None; + return std::nullopt; unsigned NumOriginalBits = X->getType()->getScalarSizeInBits(); unsigned NumExtractedBits = V->getType()->getScalarSizeInBits(); diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp index fbc2e52..1cc15fa 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -2346,7 +2346,7 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) { Pred == ICmpInst::ICMP_NE && LHS->getOpcode() == Instruction::Load && LHS->getType()->isPointerTy() && isValidAssumeForContext(II, LHS, &DT)) { - MDNode *MD = MDNode::get(II->getContext(), None); + MDNode *MD = MDNode::get(II->getContext(), std::nullopt); LHS->setMetadata(LLVMContext::MD_nonnull, MD); return RemoveConditionFromAssume(II); diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index 935c56c..db39544 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -5873,13 +5873,13 @@ InstCombiner::getFlippedStrictnessPredicateAndConstant(CmpInst::Predicate Pred, if (auto *CI = dyn_cast(C)) { // Bail out if the constant can't be safely incremented/decremented. if (!ConstantIsOk(CI)) - return llvm::None; + return std::nullopt; } else if (auto *FVTy = dyn_cast(Type)) { unsigned NumElts = FVTy->getNumElements(); for (unsigned i = 0; i != NumElts; ++i) { Constant *Elt = C->getAggregateElement(i); if (!Elt) - return llvm::None; + return std::nullopt; if (isa(Elt)) continue; @@ -5888,14 +5888,14 @@ InstCombiner::getFlippedStrictnessPredicateAndConstant(CmpInst::Predicate Pred, // know that this constant is min/max. auto *CI = dyn_cast(Elt); if (!CI || !ConstantIsOk(CI)) - return llvm::None; + return std::nullopt; if (!SafeReplacementConstant) SafeReplacementConstant = CI; } } else { // ConstantExpr? - return llvm::None; + return std::nullopt; } // It may not be safe to change a compare predicate in the presence of diff --git a/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp b/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp index 0f5269b..9c53b3f 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp @@ -522,7 +522,7 @@ std::array Negator::getSortedOperandsOfBinOp(Instruction *I) { // endless combine looping. for (Instruction *I : llvm::reverse(NewInstructions)) I->eraseFromParent(); - return llvm::None; + return std::nullopt; } return std::make_pair(ArrayRef(NewInstructions), Negated); } diff --git a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp index 8a5ddbb..17a10d2 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp @@ -871,7 +871,7 @@ Instruction *InstCombinerImpl::foldAggregateConstructionIntoAggregateReuse( if (NumAggElts > 2) return nullptr; - static constexpr auto NotFound = None; + static constexpr auto NotFound = std::nullopt; static constexpr auto FoundMismatch = nullptr; // Try to find a value of each element of an aggregate. @@ -1032,7 +1032,8 @@ Instruction *InstCombinerImpl::foldAggregateConstructionIntoAggregateReuse( Optional SourceAggregate; // Can we find the source aggregate without looking at predecessors? - SourceAggregate = FindCommonSourceAggregate(/*UseBB=*/None, /*PredBB=*/None); + SourceAggregate = FindCommonSourceAggregate(/*UseBB=*/std::nullopt, + /*PredBB=*/std::nullopt); if (Describe(SourceAggregate) != AggregateDescription::NotFound) { if (Describe(SourceAggregate) == AggregateDescription::FoundMismatch) return nullptr; // Conflicting source aggregates! diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp index f360bc4..5eb3664 100644 --- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -2888,7 +2888,7 @@ Instruction *InstCombinerImpl::visitAllocSite(Instruction &MI) { Module *M = II->getModule(); Function *F = Intrinsic::getDeclaration(M, Intrinsic::donothing); InvokeInst::Create(F, II->getNormalDest(), II->getUnwindDest(), - None, "", II->getParent()); + std::nullopt, "", II->getParent()); } // Remove debug intrinsics which describe the value contained within the @@ -4214,7 +4214,7 @@ bool InstCombinerImpl::run() { auto getOptionalSinkBlockForInst = [this](Instruction *I) -> std::optional { if (!EnableCodeSinking) - return None; + return std::nullopt; BasicBlock *BB = I->getParent(); BasicBlock *UserParent = nullptr; @@ -4224,7 +4224,7 @@ bool InstCombinerImpl::run() { if (U->isDroppable()) continue; if (NumUsers > MaxSinkNumUsers) - return None; + return std::nullopt; Instruction *UserInst = cast(U); // Special handling for Phi nodes - get the block the use occurs in. @@ -4235,14 +4235,14 @@ bool InstCombinerImpl::run() { // sophisticated analysis (i.e finding NearestCommonDominator of // these use blocks). if (UserParent && UserParent != PN->getIncomingBlock(i)) - return None; + return std::nullopt; UserParent = PN->getIncomingBlock(i); } } assert(UserParent && "expected to find user block!"); } else { if (UserParent && UserParent != UserInst->getParent()) - return None; + return std::nullopt; UserParent = UserInst->getParent(); } @@ -4252,7 +4252,7 @@ bool InstCombinerImpl::run() { // Try sinking to another block. If that block is unreachable, then do // not bother. SimplifyCFG should handle it. if (UserParent == BB || !DT.isReachableFromEntry(UserParent)) - return None; + return std::nullopt; auto *Term = UserParent->getTerminator(); // See if the user is one of our successors that has only one @@ -4264,7 +4264,7 @@ bool InstCombinerImpl::run() { // - the User will be executed at most once. // So sinking I down to User is always profitable or neutral. if (UserParent->getUniquePredecessor() != BB && !succ_empty(Term)) - return None; + return std::nullopt; assert(DT.dominates(BB, UserParent) && "Dominance relation broken?"); } @@ -4274,7 +4274,7 @@ bool InstCombinerImpl::run() { // No user or only has droppable users. if (!UserParent) - return None; + return std::nullopt; return UserParent; }; diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp index 8a63b32..94aec14 100644 --- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp @@ -1305,12 +1305,13 @@ void AddressSanitizer::getInterestingMemoryOperands( if (!ClInstrumentAtomics || ignoreAccess(I, RMW->getPointerOperand())) return; Interesting.emplace_back(I, RMW->getPointerOperandIndex(), true, - RMW->getValOperand()->getType(), None); + RMW->getValOperand()->getType(), std::nullopt); } else if (AtomicCmpXchgInst *XCHG = dyn_cast(I)) { if (!ClInstrumentAtomics || ignoreAccess(I, XCHG->getPointerOperand())) return; Interesting.emplace_back(I, XCHG->getPointerOperandIndex(), true, - XCHG->getCompareOperand()->getType(), None); + XCHG->getCompareOperand()->getType(), + std::nullopt); } else if (auto CI = dyn_cast(I)) { if (CI->getIntrinsicID() == Intrinsic::masked_load || CI->getIntrinsicID() == Intrinsic::masked_store) { diff --git a/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp index cc5e963..b58386f 100644 --- a/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp @@ -1087,8 +1087,8 @@ bool DataFlowSanitizer::initializeModule(Module &M) { Type::getInt8PtrTy(*Ctx), IntptrTy}; DFSanSetLabelFnTy = FunctionType::get(Type::getVoidTy(*Ctx), DFSanSetLabelArgs, /*isVarArg=*/false); - DFSanNonzeroLabelFnTy = - FunctionType::get(Type::getVoidTy(*Ctx), None, /*isVarArg=*/false); + DFSanNonzeroLabelFnTy = FunctionType::get(Type::getVoidTy(*Ctx), std::nullopt, + /*isVarArg=*/false); DFSanVarargWrapperFnTy = FunctionType::get( Type::getVoidTy(*Ctx), Type::getInt8PtrTy(*Ctx), /*isVarArg=*/false); DFSanConditionalCallbackFnTy = diff --git a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp index 2c0fb35..066eca3 100644 --- a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp @@ -757,12 +757,13 @@ void HWAddressSanitizer::getInterestingMemoryOperands( if (!ClInstrumentAtomics || ignoreAccess(I, RMW->getPointerOperand())) return; Interesting.emplace_back(I, RMW->getPointerOperandIndex(), true, - RMW->getValOperand()->getType(), None); + RMW->getValOperand()->getType(), std::nullopt); } else if (AtomicCmpXchgInst *XCHG = dyn_cast(I)) { if (!ClInstrumentAtomics || ignoreAccess(I, XCHG->getPointerOperand())) return; Interesting.emplace_back(I, XCHG->getPointerOperandIndex(), true, - XCHG->getCompareOperand()->getType(), None); + XCHG->getCompareOperand()->getType(), + std::nullopt); } else if (auto CI = dyn_cast(I)) { for (unsigned ArgNo = 0; ArgNo < CI->arg_size(); ArgNo++) { if (!ClInstrumentByval || !CI->isByValArgument(ArgNo) || diff --git a/llvm/lib/Transforms/Instrumentation/MemProfiler.cpp b/llvm/lib/Transforms/Instrumentation/MemProfiler.cpp index 55acc36..e9cf000 100644 --- a/llvm/lib/Transforms/Instrumentation/MemProfiler.cpp +++ b/llvm/lib/Transforms/Instrumentation/MemProfiler.cpp @@ -271,31 +271,31 @@ Optional MemProfiler::isInterestingMemoryAccess(Instruction *I) const { // Do not instrument the load fetching the dynamic shadow address. if (DynamicShadowOffset == I) - return None; + return std::nullopt; InterestingMemoryAccess Access; if (LoadInst *LI = dyn_cast(I)) { if (!ClInstrumentReads) - return None; + return std::nullopt; Access.IsWrite = false; Access.AccessTy = LI->getType(); Access.Addr = LI->getPointerOperand(); } else if (StoreInst *SI = dyn_cast(I)) { if (!ClInstrumentWrites) - return None; + return std::nullopt; Access.IsWrite = true; Access.AccessTy = SI->getValueOperand()->getType(); Access.Addr = SI->getPointerOperand(); } else if (AtomicRMWInst *RMW = dyn_cast(I)) { if (!ClInstrumentAtomics) - return None; + return std::nullopt; Access.IsWrite = true; Access.AccessTy = RMW->getValOperand()->getType(); Access.Addr = RMW->getPointerOperand(); } else if (AtomicCmpXchgInst *XCHG = dyn_cast(I)) { if (!ClInstrumentAtomics) - return None; + return std::nullopt; Access.IsWrite = true; Access.AccessTy = XCHG->getCompareOperand()->getType(); Access.Addr = XCHG->getPointerOperand(); @@ -306,14 +306,14 @@ MemProfiler::isInterestingMemoryAccess(Instruction *I) const { unsigned OpOffset = 0; if (F->getIntrinsicID() == Intrinsic::masked_store) { if (!ClInstrumentWrites) - return None; + return std::nullopt; // Masked store has an initial operand for the value. OpOffset = 1; Access.AccessTy = CI->getArgOperand(0)->getType(); Access.IsWrite = true; } else { if (!ClInstrumentReads) - return None; + return std::nullopt; Access.AccessTy = CI->getType(); Access.IsWrite = false; } @@ -325,20 +325,20 @@ MemProfiler::isInterestingMemoryAccess(Instruction *I) const { } if (!Access.Addr) - return None; + return std::nullopt; // Do not instrument accesses from different address spaces; we cannot deal // with them. Type *PtrTy = cast(Access.Addr->getType()->getScalarType()); if (PtrTy->getPointerAddressSpace() != 0) - return None; + return std::nullopt; // Ignore swifterror addresses. // swifterror memory addresses are mem2reg promoted by instruction // selection. As such they cannot have regular uses like an instrumentation // function and it makes no sense to track them as memory. if (Access.Addr->isSwiftError()) - return None; + return std::nullopt; // Peel off GEPs and BitCasts. auto *Addr = Access.Addr->stripInBoundsOffsets(); @@ -351,12 +351,12 @@ MemProfiler::isInterestingMemoryAccess(Instruction *I) const { auto OF = Triple(I->getModule()->getTargetTriple()).getObjectFormat(); if (SectionName.endswith( getInstrProfSectionName(IPSK_cnts, OF, /*AddSegmentInfo=*/false))) - return None; + return std::nullopt; } // Do not instrument accesses to LLVM internal variables. if (GV->getName().startswith("__llvm")) - return None; + return std::nullopt; } const DataLayout &DL = I->getModule()->getDataLayout(); diff --git a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp index f894881..e9939c9 100644 --- a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp @@ -4128,7 +4128,7 @@ struct MemorySanitizerVisitor : public InstVisitor { if (ArgOffset + Size > kParamTLSSize) break; const MaybeAlign ParamAlignment(CB.getParamAlign(i)); - MaybeAlign Alignment = llvm::None; + MaybeAlign Alignment = std::nullopt; if (ParamAlignment) Alignment = std::min(*ParamAlignment, kShadowTLSAlignment); Value *AShadowPtr, *AOriginPtr; diff --git a/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp b/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp index 697eacf..43f0658 100644 --- a/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp +++ b/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp @@ -251,7 +251,7 @@ private: Type *Ty); void SetNoSanitizeMetadata(Instruction *I) { - I->setMetadata(LLVMContext::MD_nosanitize, MDNode::get(*C, None)); + I->setMetadata(LLVMContext::MD_nosanitize, MDNode::get(*C, std::nullopt)); } std::string getSectionName(const std::string &Section) const; diff --git a/llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp b/llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp index cb6f6e1..ab90ef0 100644 --- a/llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp +++ b/llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp @@ -472,7 +472,8 @@ bool ObjCARCContract::tryToPeepholeInstruction( RVInstMarker->getString(), /*Constraints=*/"", /*hasSideEffects=*/true); - objcarc::createCallInstWithColors(IA, None, "", Inst, BlockColors); + objcarc::createCallInstWithColors(IA, std::nullopt, "", Inst, + BlockColors); } decline_rv_optimization: return false; diff --git a/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp b/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp index d703468..d98b15f 100644 --- a/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp +++ b/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp @@ -999,7 +999,7 @@ void ObjCARCOpt::OptimizeIndividualCallImpl( CallInst *NewCall = CallInst::Create(Decl, Call->getArgOperand(0), "", Call); NewCall->setMetadata(MDKindCache.get(ARCMDKindID::ImpreciseRelease), - MDNode::get(C, None)); + MDNode::get(C, std::nullopt)); LLVM_DEBUG(dbgs() << "Replacing autorelease{,RV}(x) with objc_release(x) " "since x is otherwise unused.\nOld: " diff --git a/llvm/lib/Transforms/Scalar/AlignmentFromAssumptions.cpp b/llvm/lib/Transforms/Scalar/AlignmentFromAssumptions.cpp index 9571e99..f419f7b 100644 --- a/llvm/lib/Transforms/Scalar/AlignmentFromAssumptions.cpp +++ b/llvm/lib/Transforms/Scalar/AlignmentFromAssumptions.cpp @@ -116,7 +116,7 @@ static MaybeAlign getNewAlignmentDiff(const SCEV *DiffSCEV, return Align(DiffUnitsAbs); } - return None; + return std::nullopt; } // There is an address given by an offset OffSCEV from AASCEV which has an diff --git a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp index ab8c72e..44d23a1 100644 --- a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp +++ b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp @@ -497,8 +497,8 @@ static void shortenAssignment(Instruction *Inst, uint64_t OldOffsetInBits, // FIXME: This should be using the DIExpression in the Alloca's dbg.assign // for the variable, since that could also contain a fragment? return *DIExpression::createFragmentExpression( - DIExpression::get(Inst->getContext(), None), DeadFragment.OffsetInBits, - DeadFragment.SizeInBits); + DIExpression::get(Inst->getContext(), std::nullopt), + DeadFragment.OffsetInBits, DeadFragment.SizeInBits); }; // A DIAssignID to use so that the inserted dbg.assign intrinsics do not @@ -1303,7 +1303,7 @@ struct DSEState { bool IsMemTerm, unsigned &PartialLimit) { if (ScanLimit == 0 || WalkerStepLimit == 0) { LLVM_DEBUG(dbgs() << "\n ... hit scan limit\n"); - return None; + return std::nullopt; } MemoryAccess *Current = StartAccess; @@ -1336,7 +1336,7 @@ struct DSEState { if (CanOptimize && Current != KillingDef->getDefiningAccess()) // The first clobbering def is... none. KillingDef->setOptimized(Current); - return None; + return std::nullopt; } // Cost of a step. Accesses in the same block are more likely to be valid @@ -1346,7 +1346,7 @@ struct DSEState { : MemorySSAOtherBBStepCost; if (WalkerStepLimit <= StepCost) { LLVM_DEBUG(dbgs() << " ... hit walker step limit\n"); - return None; + return std::nullopt; } WalkerStepLimit -= StepCost; @@ -1371,14 +1371,14 @@ struct DSEState { // instructions that block us from DSEing if (mayThrowBetween(KillingI, CurrentI, KillingUndObj)) { LLVM_DEBUG(dbgs() << " ... skip, may throw!\n"); - return None; + return std::nullopt; } // Check for anything that looks like it will be a barrier to further // removal if (isDSEBarrier(KillingUndObj, CurrentI)) { LLVM_DEBUG(dbgs() << " ... skip, barrier\n"); - return None; + return std::nullopt; } // If Current is known to be on path that reads DefLoc or is a read @@ -1386,7 +1386,7 @@ struct DSEState { // for intrinsic calls, because the code knows how to handle memcpy // intrinsics. if (!isa(CurrentI) && isReadClobber(KillingLoc, CurrentI)) - return None; + return std::nullopt; // Quick check if there are direct uses that are read-clobbers. if (any_of(Current->uses(), [this, &KillingLoc, StartAccess](Use &U) { @@ -1396,7 +1396,7 @@ struct DSEState { return false; })) { LLVM_DEBUG(dbgs() << " ... found a read clobber\n"); - return None; + return std::nullopt; } // If Current does not have an analyzable write location or is not @@ -1490,7 +1490,7 @@ struct DSEState { // Bail out if the number of accesses to check exceeds the scan limit. if (ScanLimit < (WorkList.size() - I)) { LLVM_DEBUG(dbgs() << "\n ... hit scan limit\n"); - return None; + return std::nullopt; } --ScanLimit; NumDomMemDefChecks++; @@ -1535,14 +1535,14 @@ struct DSEState { if (UseInst->mayThrow() && !isInvisibleToCallerOnUnwind(KillingUndObj)) { LLVM_DEBUG(dbgs() << " ... found throwing instruction\n"); - return None; + return std::nullopt; } // Uses which may read the original MemoryDef mean we cannot eliminate the // original MD. Stop walk. if (isReadClobber(MaybeDeadLoc, UseInst)) { LLVM_DEBUG(dbgs() << " ... found read clobber\n"); - return None; + return std::nullopt; } // If this worklist walks back to the original memory access (and the @@ -1551,7 +1551,7 @@ struct DSEState { if (MaybeDeadAccess == UseAccess && !isGuaranteedLoopInvariant(MaybeDeadLoc.Ptr)) { LLVM_DEBUG(dbgs() << " ... found not loop invariant self access\n"); - return None; + return std::nullopt; } // Otherwise, for the KillingDef and MaybeDeadAccess we only have to check // if it reads the memory location. @@ -1585,7 +1585,7 @@ struct DSEState { } else { LLVM_DEBUG(dbgs() << " ... found preceeding def " << *UseInst << "\n"); - return None; + return std::nullopt; } } else PushMemUses(UseDef); @@ -1615,7 +1615,7 @@ struct DSEState { // killing block. if (!PDT.dominates(CommonPred, MaybeDeadAccess->getBlock())) { if (!AnyUnreachableExit) - return None; + return std::nullopt; // Fall back to CFG scan starting at all non-unreachable roots if not // all paths to the exit go through CommonPred. @@ -1646,7 +1646,7 @@ struct DSEState { if (KillingBlocks.count(Current)) continue; if (Current == MaybeDeadAccess->getBlock()) - return None; + return std::nullopt; // MaybeDeadAccess is reachable from the entry, so we don't have to // explore unreachable blocks further. @@ -1657,7 +1657,7 @@ struct DSEState { WorkList.insert(Pred); if (WorkList.size() >= MemorySSAPathCheckLimit) - return None; + return std::nullopt; } NumCFGSuccess++; } diff --git a/llvm/lib/Transforms/Scalar/Float2Int.cpp b/llvm/lib/Transforms/Scalar/Float2Int.cpp index 56f2a3b..432d53e 100644 --- a/llvm/lib/Transforms/Scalar/Float2Int.cpp +++ b/llvm/lib/Transforms/Scalar/Float2Int.cpp @@ -243,7 +243,7 @@ Optional Float2IntPass::calcRange(Instruction *I) { auto OpIt = SeenInsts.find(OI); assert(OpIt != SeenInsts.end() && "def not seen before use!"); if (OpIt->second == unknownRange()) - return None; // Wait until operand range has been calculated. + return std::nullopt; // Wait until operand range has been calculated. OpRanges.push_back(OpIt->second); } else if (ConstantFP *CF = dyn_cast(O)) { // Work out if the floating point number can be losslessly represented diff --git a/llvm/lib/Transforms/Scalar/GVN.cpp b/llvm/lib/Transforms/Scalar/GVN.cpp index 434bd38..c382814 100644 --- a/llvm/lib/Transforms/Scalar/GVN.cpp +++ b/llvm/lib/Transforms/Scalar/GVN.cpp @@ -763,14 +763,14 @@ void GVNPass::printPipeline( OS, MapClassName2PassName); OS << "<"; - if (Options.AllowPRE != None) + if (Options.AllowPRE != std::nullopt) OS << (Options.AllowPRE.value() ? "" : "no-") << "pre;"; - if (Options.AllowLoadPRE != None) + if (Options.AllowLoadPRE != std::nullopt) OS << (Options.AllowLoadPRE.value() ? "" : "no-") << "load-pre;"; - if (Options.AllowLoadPRESplitBackedge != None) + if (Options.AllowLoadPRESplitBackedge != std::nullopt) OS << (Options.AllowLoadPRESplitBackedge.value() ? "" : "no-") << "split-backedge-load-pre;"; - if (Options.AllowMemDep != None) + if (Options.AllowMemDep != std::nullopt) OS << (Options.AllowMemDep.value() ? "" : "no-") << "memdep"; OS << ">"; } @@ -1129,12 +1129,12 @@ tryToConvertLoadOfPtrSelect(BasicBlock *DepBB, BasicBlock::iterator End, auto *Sel = dyn_cast_or_null(Address); if (!Sel || DepBB != Sel->getParent()) - return None; + return std::nullopt; LoadInst *L1 = findDominatingLoad(Sel->getOperand(1), LoadTy, Sel, DT); LoadInst *L2 = findDominatingLoad(Sel->getOperand(2), LoadTy, Sel, DT); if (!L1 || !L2) - return None; + return std::nullopt; // Ensure there are no accesses that may modify the locations referenced by // either L1 or L2 between L1, L2 and the specified End iterator. @@ -1145,7 +1145,7 @@ tryToConvertLoadOfPtrSelect(BasicBlock *DepBB, BasicBlock::iterator End, return isModSet(AA->getModRefInfo(&I, L1Loc)) || isModSet(AA->getModRefInfo(&I, L2Loc)); })) - return None; + return std::nullopt; return AvailableValue::getSelect(Sel); } @@ -1204,7 +1204,9 @@ bool GVNPass::AnalyzeLoadAvailability(LoadInst *Load, MemDepResult DepInfo, canCoerceMustAliasedValueToLoad(DepLoad, LoadType, DL)) { const auto ClobberOff = MD->getClobberOffset(DepLoad); // GVN has no deal with a negative offset. - Offset = (ClobberOff == None || *ClobberOff < 0) ? -1 : *ClobberOff; + Offset = (ClobberOff == std::nullopt || *ClobberOff < 0) + ? -1 + : *ClobberOff; } if (Offset == -1) Offset = diff --git a/llvm/lib/Transforms/Scalar/GVNSink.cpp b/llvm/lib/Transforms/Scalar/GVNSink.cpp index 891f7d7..4fba9f81 100644 --- a/llvm/lib/Transforms/Scalar/GVNSink.cpp +++ b/llvm/lib/Transforms/Scalar/GVNSink.cpp @@ -654,7 +654,7 @@ Optional GVNSink::analyzeInstructionForSinking( uint32_t N = VN.lookupOrAdd(I); LLVM_DEBUG(dbgs() << " VN=" << Twine::utohexstr(N) << " for" << *I << "\n"); if (N == ~0U) - return None; + return std::nullopt; VNums[N]++; } unsigned VNumToSink = @@ -662,7 +662,7 @@ Optional GVNSink::analyzeInstructionForSinking( if (VNums[VNumToSink] == 1) // Can't sink anything! - return None; + return std::nullopt; // Now restrict the number of incoming blocks down to only those with // VNumToSink. @@ -677,7 +677,7 @@ Optional GVNSink::analyzeInstructionForSinking( } for (auto *I : NewInsts) if (shouldAvoidSinkingInstruction(I)) - return None; + return std::nullopt; // If we've restricted the incoming blocks, restrict all needed PHIs also // to that set. @@ -715,7 +715,7 @@ Optional GVNSink::analyzeInstructionForSinking( // V exists in this PHI, but the whole PHI is different to NewPHI // (else it would have been removed earlier). We cannot continue // because this isn't representable. - return None; + return std::nullopt; // Which operands need PHIs? // FIXME: If any of these fail, we should partition up the candidates to @@ -728,7 +728,7 @@ Optional GVNSink::analyzeInstructionForSinking( return I->getNumOperands() != I0->getNumOperands(); }; if (any_of(NewInsts, hasDifferentNumOperands)) - return None; + return std::nullopt; for (unsigned OpNum = 0, E = I0->getNumOperands(); OpNum != E; ++OpNum) { ModelledPHI PHI(NewInsts, OpNum, ActivePreds); @@ -736,15 +736,15 @@ Optional GVNSink::analyzeInstructionForSinking( continue; if (!canReplaceOperandWithVariable(I0, OpNum)) // We can 't create a PHI from this instruction! - return None; + return std::nullopt; if (NeededPHIs.count(PHI)) continue; if (!PHI.areAllIncomingValuesSameType()) - return None; + return std::nullopt; // Don't create indirect calls! The called value is the final operand. if ((isa(I0) || isa(I0)) && OpNum == E - 1 && PHI.areAnyIncomingValuesConstant()) - return None; + return std::nullopt; NeededPHIs.reserve(NeededPHIs.size()); NeededPHIs.insert(PHI); diff --git a/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp b/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp index b50d197..a89424c 100644 --- a/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp +++ b/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp @@ -246,7 +246,7 @@ class InductiveRangeCheckElimination { public: InductiveRangeCheckElimination(ScalarEvolution &SE, BranchProbabilityInfo *BPI, DominatorTree &DT, - LoopInfo &LI, GetBFIFunc GetBFI = None) + LoopInfo &LI, GetBFIFunc GetBFI = std::nullopt) : SE(SE), BPI(BPI), DT(DT), LI(LI), GetBFI(GetBFI) {} bool run(Loop *L, function_ref LPMAddNewLoop); @@ -753,7 +753,7 @@ LoopStructure::parseLoopStructure(ScalarEvolution &SE, Loop &L, const char *&FailureReason) { if (!L.isLoopSimplifyForm()) { FailureReason = "loop not in LoopSimplify form"; - return None; + return std::nullopt; } BasicBlock *Latch = L.getLoopLatch(); @@ -761,25 +761,25 @@ LoopStructure::parseLoopStructure(ScalarEvolution &SE, Loop &L, if (Latch->getTerminator()->getMetadata(ClonedLoopTag)) { FailureReason = "loop has already been cloned"; - return None; + return std::nullopt; } if (!L.isLoopExiting(Latch)) { FailureReason = "no loop latch"; - return None; + return std::nullopt; } BasicBlock *Header = L.getHeader(); BasicBlock *Preheader = L.getLoopPreheader(); if (!Preheader) { FailureReason = "no preheader"; - return None; + return std::nullopt; } BranchInst *LatchBr = dyn_cast(Latch->getTerminator()); if (!LatchBr || LatchBr->isUnconditional()) { FailureReason = "latch terminator not conditional branch"; - return None; + return std::nullopt; } unsigned LatchBrExitIdx = LatchBr->getSuccessor(0) == Header ? 1 : 0; @@ -787,13 +787,13 @@ LoopStructure::parseLoopStructure(ScalarEvolution &SE, Loop &L, ICmpInst *ICI = dyn_cast(LatchBr->getCondition()); if (!ICI || !isa(ICI->getOperand(0)->getType())) { FailureReason = "latch terminator branch not conditional on integral icmp"; - return None; + return std::nullopt; } const SCEV *LatchCount = SE.getExitCount(&L, Latch); if (isa(LatchCount)) { FailureReason = "could not compute latch count"; - return None; + return std::nullopt; } ICmpInst::Predicate Pred = ICI->getPredicate(); @@ -812,7 +812,7 @@ LoopStructure::parseLoopStructure(ScalarEvolution &SE, Loop &L, Pred = ICmpInst::getSwappedPredicate(Pred); } else { FailureReason = "no add recurrences in the icmp"; - return None; + return std::nullopt; } } @@ -848,22 +848,22 @@ LoopStructure::parseLoopStructure(ScalarEvolution &SE, Loop &L, const SCEVAddRecExpr *IndVarBase = cast(LeftSCEV); if (IndVarBase->getLoop() != &L) { FailureReason = "LHS in cmp is not an AddRec for this loop"; - return None; + return std::nullopt; } if (!IndVarBase->isAffine()) { FailureReason = "LHS in icmp not induction variable"; - return None; + return std::nullopt; } const SCEV* StepRec = IndVarBase->getStepRecurrence(SE); if (!isa(StepRec)) { FailureReason = "LHS in icmp not induction variable"; - return None; + return std::nullopt; } ConstantInt *StepCI = cast(StepRec)->getValue(); if (ICI->isEquality() && !HasNoSignedWrap(IndVarBase)) { FailureReason = "LHS in icmp needs nsw for equality predicates"; - return None; + return std::nullopt; } assert(!StepCI->isZero() && "Zero step?"); @@ -926,19 +926,19 @@ LoopStructure::parseLoopStructure(ScalarEvolution &SE, Loop &L, if (!FoundExpectedPred) { FailureReason = "expected icmp slt semantically, found something else"; - return None; + return std::nullopt; } IsSignedPredicate = ICmpInst::isSigned(Pred); if (!IsSignedPredicate && !AllowUnsignedLatchCondition) { FailureReason = "unsigned latch conditions are explicitly prohibited"; - return None; + return std::nullopt; } if (!isSafeIncreasingBound(IndVarStart, RightSCEV, Step, Pred, LatchBrExitIdx, &L, SE)) { FailureReason = "Unsafe loop bounds"; - return None; + return std::nullopt; } if (LatchBrExitIdx == 0) { // We need to increase the right value unless we have already decreased @@ -989,7 +989,7 @@ LoopStructure::parseLoopStructure(ScalarEvolution &SE, Loop &L, if (!FoundExpectedPred) { FailureReason = "expected icmp sgt semantically, found something else"; - return None; + return std::nullopt; } IsSignedPredicate = @@ -997,13 +997,13 @@ LoopStructure::parseLoopStructure(ScalarEvolution &SE, Loop &L, if (!IsSignedPredicate && !AllowUnsignedLatchCondition) { FailureReason = "unsigned latch conditions are explicitly prohibited"; - return None; + return std::nullopt; } if (!isSafeDecreasingBound(IndVarStart, RightSCEV, Step, Pred, LatchBrExitIdx, &L, SE)) { FailureReason = "Unsafe bounds"; - return None; + return std::nullopt; } if (LatchBrExitIdx == 0) { @@ -1070,9 +1070,9 @@ LoopConstrainer::calculateSubRanges(bool IsSignedPredicate) const { // We only support wide range checks and narrow latches. if (!AllowNarrowLatchCondition && RTy != Ty) - return None; + return std::nullopt; if (RTy->getBitWidth() < Ty->getBitWidth()) - return None; + return std::nullopt; LoopConstrainer::SubRanges Result; @@ -1592,9 +1592,9 @@ InductiveRangeCheck::computeSafeIterationSpace( auto *RCType = dyn_cast(getBegin()->getType()); // Do not work with pointer types. if (!IVType || !RCType) - return None; + return std::nullopt; if (IVType->getBitWidth() > RCType->getBitWidth()) - return None; + return std::nullopt; // IndVar is of the form "A + B * I" (where "I" is the canonical induction // variable, that may or may not exist as a real llvm::Value in the loop) and // this inductive range check is a range check on the "C + D * I" ("C" is @@ -1616,19 +1616,19 @@ InductiveRangeCheck::computeSafeIterationSpace( // to deal with overflown values. if (!IndVar->isAffine()) - return None; + return std::nullopt; const SCEV *A = NoopOrExtend(IndVar->getStart(), RCType, SE, IsLatchSigned); const SCEVConstant *B = dyn_cast( NoopOrExtend(IndVar->getStepRecurrence(SE), RCType, SE, IsLatchSigned)); if (!B) - return None; + return std::nullopt; assert(!B->isZero() && "Recurrence with zero step?"); const SCEV *C = getBegin(); const SCEVConstant *D = dyn_cast(getStep()); if (D != B) - return None; + return std::nullopt; assert(!D->getValue()->isZero() && "Recurrence with zero step?"); unsigned BitWidth = RCType->getBitWidth(); @@ -1716,7 +1716,7 @@ IntersectSignedRange(ScalarEvolution &SE, const Optional &R1, const InductiveRangeCheck::Range &R2) { if (R2.isEmpty(SE, /* IsSigned */ true)) - return None; + return std::nullopt; if (!R1) return R2; auto &R1Value = R1.value(); @@ -1728,7 +1728,7 @@ IntersectSignedRange(ScalarEvolution &SE, // TODO: we could widen the smaller range and have this work; but for now we // bail out to keep things simple. if (R1Value.getType() != R2.getType()) - return None; + return std::nullopt; const SCEV *NewBegin = SE.getSMaxExpr(R1Value.getBegin(), R2.getBegin()); const SCEV *NewEnd = SE.getSMinExpr(R1Value.getEnd(), R2.getEnd()); @@ -1736,7 +1736,7 @@ IntersectSignedRange(ScalarEvolution &SE, // If the resulting range is empty, just return None. auto Ret = InductiveRangeCheck::Range(NewBegin, NewEnd); if (Ret.isEmpty(SE, /* IsSigned */ true)) - return None; + return std::nullopt; return Ret; } @@ -1745,7 +1745,7 @@ IntersectUnsignedRange(ScalarEvolution &SE, const Optional &R1, const InductiveRangeCheck::Range &R2) { if (R2.isEmpty(SE, /* IsSigned */ false)) - return None; + return std::nullopt; if (!R1) return R2; auto &R1Value = R1.value(); @@ -1757,7 +1757,7 @@ IntersectUnsignedRange(ScalarEvolution &SE, // TODO: we could widen the smaller range and have this work; but for now we // bail out to keep things simple. if (R1Value.getType() != R2.getType()) - return None; + return std::nullopt; const SCEV *NewBegin = SE.getUMaxExpr(R1Value.getBegin(), R2.getBegin()); const SCEV *NewEnd = SE.getUMinExpr(R1Value.getEnd(), R2.getEnd()); @@ -1765,7 +1765,7 @@ IntersectUnsignedRange(ScalarEvolution &SE, // If the resulting range is empty, just return None. auto Ret = InductiveRangeCheck::Range(NewBegin, NewEnd); if (Ret.isEmpty(SE, /* IsSigned */ false)) - return None; + return std::nullopt; return Ret; } diff --git a/llvm/lib/Transforms/Scalar/LoopFuse.cpp b/llvm/lib/Transforms/Scalar/LoopFuse.cpp index 70903f5..5f64260 100644 --- a/llvm/lib/Transforms/Scalar/LoopFuse.cpp +++ b/llvm/lib/Transforms/Scalar/LoopFuse.cpp @@ -645,7 +645,7 @@ private: void collectFusionCandidates(const LoopVector &LV) { for (Loop *L : LV) { TTI::PeelingPreferences PP = - gatherPeelingPreferences(L, SE, TTI, None, None); + gatherPeelingPreferences(L, SE, TTI, std::nullopt, std::nullopt); FusionCandidate CurrCand(L, DT, &PDT, ORE, PP); if (!CurrCand.isEligibleForFusion(SE)) continue; @@ -708,14 +708,14 @@ private: if (isa(TripCount0)) { UncomputableTripCount++; LLVM_DEBUG(dbgs() << "Trip count of first loop could not be computed!"); - return {false, None}; + return {false, std::nullopt}; } const SCEV *TripCount1 = SE.getBackedgeTakenCount(FC1.L); if (isa(TripCount1)) { UncomputableTripCount++; LLVM_DEBUG(dbgs() << "Trip count of second loop could not be computed!"); - return {false, None}; + return {false, std::nullopt}; } LLVM_DEBUG(dbgs() << "\tTrip counts: " << *TripCount0 << " & " @@ -740,7 +740,7 @@ private: LLVM_DEBUG(dbgs() << "Loop(s) do not have a single exit point or do not " "have a constant number of iterations. Peeling " "is not benefical\n"); - return {false, None}; + return {false, std::nullopt}; } Optional Difference; diff --git a/llvm/lib/Transforms/Scalar/LoopPredication.cpp b/llvm/lib/Transforms/Scalar/LoopPredication.cpp index 77503a5..a5dddbe 100644 --- a/llvm/lib/Transforms/Scalar/LoopPredication.cpp +++ b/llvm/lib/Transforms/Scalar/LoopPredication.cpp @@ -392,10 +392,10 @@ LoopPredication::parseLoopICmp(ICmpInst *ICI) { const SCEV *LHSS = SE->getSCEV(LHS); if (isa(LHSS)) - return None; + return std::nullopt; const SCEV *RHSS = SE->getSCEV(RHS); if (isa(RHSS)) - return None; + return std::nullopt; // Canonicalize RHS to be loop invariant bound, LHS - a loop computable IV if (SE->isLoopInvariant(LHSS, L)) { @@ -406,7 +406,7 @@ LoopPredication::parseLoopICmp(ICmpInst *ICI) { const SCEVAddRecExpr *AR = dyn_cast(LHSS); if (!AR || AR->getLoop() != L) - return None; + return std::nullopt; return LoopICmp(Pred, AR, RHSS); } @@ -494,9 +494,9 @@ static std::optional generateLoopLatchCheck(const DataLayout &DL, // For now, bail out if latch type is narrower than range type. if (DL.getTypeSizeInBits(LatchType).getFixedSize() < DL.getTypeSizeInBits(RangeCheckType).getFixedSize()) - return None; + return std::nullopt; if (!isSafeToTruncateWideIVType(DL, SE, LatchCheck, RangeCheckType)) - return None; + return std::nullopt; // We can now safely identify the truncated version of the IV and limit for // RangeCheckType. LoopICmp NewLatchCheck; @@ -504,7 +504,7 @@ static std::optional generateLoopLatchCheck(const DataLayout &DL, NewLatchCheck.IV = dyn_cast( SE.getTruncateExpr(LatchCheck.IV, RangeCheckType)); if (!NewLatchCheck.IV) - return None; + return std::nullopt; NewLatchCheck.Limit = SE.getTruncateExpr(LatchCheck.Limit, RangeCheckType); LLVM_DEBUG(dbgs() << "IV of type: " << *LatchType << "can be represented as range check type:" @@ -598,12 +598,12 @@ Optional LoopPredication::widenICmpRangeCheckIncrementingLoop( !isLoopInvariantValue(LatchStart) || !isLoopInvariantValue(LatchLimit)) { LLVM_DEBUG(dbgs() << "Can't expand limit check!\n"); - return None; + return std::nullopt; } if (!Expander.isSafeToExpandAt(LatchStart, Guard) || !Expander.isSafeToExpandAt(LatchLimit, Guard)) { LLVM_DEBUG(dbgs() << "Can't expand limit check!\n"); - return None; + return std::nullopt; } // guardLimit - guardStart + latchStart - 1 @@ -641,12 +641,12 @@ Optional LoopPredication::widenICmpRangeCheckDecrementingLoop( !isLoopInvariantValue(LatchStart) || !isLoopInvariantValue(LatchLimit)) { LLVM_DEBUG(dbgs() << "Can't expand limit check!\n"); - return None; + return std::nullopt; } if (!Expander.isSafeToExpandAt(LatchStart, Guard) || !Expander.isSafeToExpandAt(LatchLimit, Guard)) { LLVM_DEBUG(dbgs() << "Can't expand limit check!\n"); - return None; + return std::nullopt; } // The decrement of the latch check IV should be the same as the // rangeCheckIV. @@ -655,7 +655,7 @@ Optional LoopPredication::widenICmpRangeCheckDecrementingLoop( LLVM_DEBUG(dbgs() << "Not the same. PostDecLatchCheckIV: " << *PostDecLatchCheckIV << " and RangeCheckIV: " << *RangeCheck.IV << "\n"); - return None; + return std::nullopt; } // Generate the widened condition for CountDownLoop: @@ -701,26 +701,26 @@ Optional LoopPredication::widenICmpRangeCheck(ICmpInst *ICI, auto RangeCheck = parseLoopICmp(ICI); if (!RangeCheck) { LLVM_DEBUG(dbgs() << "Failed to parse the loop latch condition!\n"); - return None; + return std::nullopt; } LLVM_DEBUG(dbgs() << "Guard check:\n"); LLVM_DEBUG(RangeCheck->dump()); if (RangeCheck->Pred != ICmpInst::ICMP_ULT) { LLVM_DEBUG(dbgs() << "Unsupported range check predicate(" << RangeCheck->Pred << ")!\n"); - return None; + return std::nullopt; } auto *RangeCheckIV = RangeCheck->IV; if (!RangeCheckIV->isAffine()) { LLVM_DEBUG(dbgs() << "Range check IV is not affine!\n"); - return None; + return std::nullopt; } auto *Step = RangeCheckIV->getStepRecurrence(*SE); // We cannot just compare with latch IV step because the latch and range IVs // may have different types. if (!isSupportedStep(Step)) { LLVM_DEBUG(dbgs() << "Range check and latch have IVs different steps!\n"); - return None; + return std::nullopt; } auto *Ty = RangeCheckIV->getType(); auto CurrLatchCheckOpt = generateLoopLatchCheck(*DL, *SE, LatchCheck, Ty); @@ -728,7 +728,7 @@ Optional LoopPredication::widenICmpRangeCheck(ICmpInst *ICI, LLVM_DEBUG(dbgs() << "Failed to generate a loop latch check " "corresponding to range type: " << *Ty << "\n"); - return None; + return std::nullopt; } LoopICmp CurrLatchCheck = *CurrLatchCheckOpt; @@ -739,7 +739,7 @@ Optional LoopPredication::widenICmpRangeCheck(ICmpInst *ICI, "Range and latch steps should be of same type!"); if (Step != CurrLatchCheck.IV->getStepRecurrence(*SE)) { LLVM_DEBUG(dbgs() << "Range and latch have different step values!\n"); - return None; + return std::nullopt; } if (Step->isOne()) @@ -879,13 +879,13 @@ Optional LoopPredication::parseLoopLatchICmp() { BasicBlock *LoopLatch = L->getLoopLatch(); if (!LoopLatch) { LLVM_DEBUG(dbgs() << "The loop doesn't have a single latch!\n"); - return None; + return std::nullopt; } auto *BI = dyn_cast(LoopLatch->getTerminator()); if (!BI || !BI->isConditional()) { LLVM_DEBUG(dbgs() << "Failed to match the latch terminator!\n"); - return None; + return std::nullopt; } BasicBlock *TrueDest = BI->getSuccessor(0); assert( @@ -895,12 +895,12 @@ Optional LoopPredication::parseLoopLatchICmp() { auto *ICI = dyn_cast(BI->getCondition()); if (!ICI) { LLVM_DEBUG(dbgs() << "Failed to match the latch condition!\n"); - return None; + return std::nullopt; } auto Result = parseLoopICmp(ICI); if (!Result) { LLVM_DEBUG(dbgs() << "Failed to parse the loop latch condition!\n"); - return None; + return std::nullopt; } if (TrueDest != L->getHeader()) @@ -910,13 +910,13 @@ Optional LoopPredication::parseLoopLatchICmp() { // recurrence. if (!Result->IV->isAffine()) { LLVM_DEBUG(dbgs() << "The induction variable is not affine!\n"); - return None; + return std::nullopt; } auto *Step = Result->IV->getStepRecurrence(*SE); if (!isSupportedStep(Step)) { LLVM_DEBUG(dbgs() << "Unsupported loop stride(" << *Step << ")!\n"); - return None; + return std::nullopt; } auto IsUnsupportedPredicate = [](const SCEV *Step, ICmpInst::Predicate Pred) { @@ -934,7 +934,7 @@ Optional LoopPredication::parseLoopLatchICmp() { if (IsUnsupportedPredicate(Step, Result->Pred)) { LLVM_DEBUG(dbgs() << "Unsupported loop latch predicate(" << Result->Pred << ")!\n"); - return None; + return std::nullopt; } return Result; diff --git a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp index 20aa801..72779ab 100644 --- a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp +++ b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp @@ -6620,17 +6620,17 @@ canFoldTermCondOfLoop(Loop *L, ScalarEvolution &SE, DominatorTree &DT, const LoopInfo &LI) { if (!L->isInnermost()) { LLVM_DEBUG(dbgs() << "Cannot fold on non-innermost loop\n"); - return None; + return std::nullopt; } // Only inspect on simple loop structure if (!L->isLoopSimplifyForm()) { LLVM_DEBUG(dbgs() << "Cannot fold on non-simple loop\n"); - return None; + return std::nullopt; } if (!SE.hasLoopInvariantBackedgeTakenCount(L)) { LLVM_DEBUG(dbgs() << "Cannot fold on backedge that is loop variant\n"); - return None; + return std::nullopt; } BasicBlock *LoopPreheader = L->getLoopPreheader(); @@ -6640,18 +6640,18 @@ canFoldTermCondOfLoop(Loop *L, ScalarEvolution &SE, DominatorTree &DT, // Terminating condition is foldable when it is an eq/ne icmp BranchInst *BI = cast(LoopLatch->getTerminator()); if (BI->isUnconditional()) - return None; + return std::nullopt; Value *TermCond = BI->getCondition(); if (!isa(TermCond) || !cast(TermCond)->isEquality()) { LLVM_DEBUG(dbgs() << "Cannot fold on branching condition that is not an " "ICmpInst::eq / ICmpInst::ne\n"); - return None; + return std::nullopt; } if (!TermCond->hasOneUse()) { LLVM_DEBUG( dbgs() << "Cannot replace terminating condition with more than one use\n"); - return None; + return std::nullopt; } // For `IsToFold`, a primary IV can be replaced by other affine AddRec when it @@ -6769,7 +6769,7 @@ canFoldTermCondOfLoop(Loop *L, ScalarEvolution &SE, DominatorTree &DT, << " ToHelpFold: " << *ToHelpFold << "\n"); if (!ToFold || !ToHelpFold) - return None; + return std::nullopt; return {{ToFold, {ToHelpFold, TermValueS}}}; } diff --git a/llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp b/llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp index 81018d7..596e0d4 100644 --- a/llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp +++ b/llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp @@ -284,11 +284,11 @@ tryToUnrollAndJamLoop(Loop *L, DominatorTree &DT, LoopInfo *LI, ScalarEvolution &SE, const TargetTransformInfo &TTI, AssumptionCache &AC, DependenceInfo &DI, OptimizationRemarkEmitter &ORE, int OptLevel) { - TargetTransformInfo::UnrollingPreferences UP = - gatherUnrollingPreferences(L, SE, TTI, nullptr, nullptr, ORE, OptLevel, - None, None, None, None, None, None); + TargetTransformInfo::UnrollingPreferences UP = gatherUnrollingPreferences( + L, SE, TTI, nullptr, nullptr, ORE, OptLevel, std::nullopt, std::nullopt, + std::nullopt, std::nullopt, std::nullopt, std::nullopt); TargetTransformInfo::PeelingPreferences PP = - gatherPeelingPreferences(L, SE, TTI, None, None); + gatherPeelingPreferences(L, SE, TTI, std::nullopt, std::nullopt); TransformationMode EnableMode = hasUnrollAndJamTransformation(L); if (EnableMode & TM_Disable) diff --git a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp index 35a1a8d..148af5a9 100644 --- a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp +++ b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp @@ -359,11 +359,11 @@ static Optional analyzeLoopUnrollCost( // Only analyze inner loops. We can't properly estimate cost of nested loops // and we won't visit inner loops again anyway. if (!L->isInnermost()) - return None; + return std::nullopt; // Don't simulate loops with a big or unknown tripcount if (!TripCount || TripCount > MaxIterationsCountToAnalyze) - return None; + return std::nullopt; SmallSetVector BBWorklist; SmallSetVector, 4> ExitWorklist; @@ -559,7 +559,7 @@ static Optional analyzeLoopUnrollCost( const Function *Callee = CI->getCalledFunction(); if (!Callee || TTI.isLoweredToCall(Callee)) { LLVM_DEBUG(dbgs() << "Can't analyze cost of loop with call\n"); - return None; + return std::nullopt; } } @@ -574,7 +574,7 @@ static Optional analyzeLoopUnrollCost( << " UnrolledCost: " << UnrolledCost << ", MaxUnrolledLoopSize: " << MaxUnrolledLoopSize << "\n"); - return None; + return std::nullopt; } } @@ -632,7 +632,7 @@ static Optional analyzeLoopUnrollCost( if (UnrolledCost == RolledDynamicCost) { LLVM_DEBUG(dbgs() << " No opportunities found.. exiting.\n" << " UnrolledCost: " << UnrolledCost << "\n"); - return None; + return std::nullopt; } } @@ -798,7 +798,7 @@ shouldPragmaUnroll(Loop *L, const PragmaInfo &PInfo, return TripCount; // if didn't return until here, should continue to other priorties - return None; + return std::nullopt; } static std::optional shouldFullUnroll( @@ -809,7 +809,7 @@ static std::optional shouldFullUnroll( assert(FullUnrollTripCount && "should be non-zero!"); if (FullUnrollTripCount > UP.FullUnrollMaxCount) - return None; + return std::nullopt; // When computing the unrolled size, note that BEInsns are not replicated // like the rest of the loop body. @@ -828,7 +828,7 @@ static std::optional shouldFullUnroll( if (Cost->UnrolledCost < UP.Threshold * Boost / 100) return FullUnrollTripCount; } - return None; + return std::nullopt; } static std::optional @@ -837,7 +837,7 @@ shouldPartialUnroll(const unsigned LoopSize, const unsigned TripCount, const TargetTransformInfo::UnrollingPreferences &UP) { if (!TripCount) - return None; + return std::nullopt; if (!UP.Partial) { LLVM_DEBUG(dbgs() << " will not try to unroll partially because " @@ -1378,13 +1378,15 @@ public: Optional ProvidedFullUnrollMaxCount; LoopUnroll(int OptLevel = 2, bool OnlyWhenForced = false, - bool ForgetAllSCEV = false, Optional Threshold = None, - Optional Count = None, - Optional AllowPartial = None, Optional Runtime = None, - Optional UpperBound = None, - Optional AllowPeeling = None, - Optional AllowProfileBasedPeeling = None, - Optional ProvidedFullUnrollMaxCount = None) + bool ForgetAllSCEV = false, + Optional Threshold = std::nullopt, + Optional Count = std::nullopt, + Optional AllowPartial = std::nullopt, + Optional Runtime = std::nullopt, + Optional UpperBound = std::nullopt, + Optional AllowPeeling = std::nullopt, + Optional AllowProfileBasedPeeling = std::nullopt, + Optional ProvidedFullUnrollMaxCount = std::nullopt) : LoopPass(ID), OptLevel(OptLevel), OnlyWhenForced(OnlyWhenForced), ForgetAllSCEV(ForgetAllSCEV), ProvidedCount(std::move(Count)), ProvidedThreshold(Threshold), ProvidedAllowPartial(AllowPartial), @@ -1456,12 +1458,12 @@ Pass *llvm::createLoopUnrollPass(int OptLevel, bool OnlyWhenForced, // callers. return new LoopUnroll( OptLevel, OnlyWhenForced, ForgetAllSCEV, - Threshold == -1 ? None : Optional(Threshold), - Count == -1 ? None : Optional(Count), - AllowPartial == -1 ? None : Optional(AllowPartial), - Runtime == -1 ? None : Optional(Runtime), - UpperBound == -1 ? None : Optional(UpperBound), - AllowPeeling == -1 ? None : Optional(AllowPeeling)); + Threshold == -1 ? std::nullopt : Optional(Threshold), + Count == -1 ? std::nullopt : Optional(Count), + AllowPartial == -1 ? std::nullopt : Optional(AllowPartial), + Runtime == -1 ? std::nullopt : Optional(Runtime), + UpperBound == -1 ? std::nullopt : Optional(UpperBound), + AllowPeeling == -1 ? std::nullopt : Optional(AllowPeeling)); } Pass *llvm::createSimpleLoopUnrollPass(int OptLevel, bool OnlyWhenForced, @@ -1489,16 +1491,17 @@ PreservedAnalyses LoopFullUnrollPass::run(Loop &L, LoopAnalysisManager &AM, std::string LoopName = std::string(L.getName()); - bool Changed = tryToUnrollLoop(&L, AR.DT, &AR.LI, AR.SE, AR.TTI, AR.AC, ORE, - /*BFI*/ nullptr, /*PSI*/ nullptr, - /*PreserveLCSSA*/ true, OptLevel, - OnlyWhenForced, ForgetSCEV, /*Count*/ None, - /*Threshold*/ None, /*AllowPartial*/ false, - /*Runtime*/ false, /*UpperBound*/ false, - /*AllowPeeling*/ true, - /*AllowProfileBasedPeeling*/ false, - /*FullUnrollMaxCount*/ None) != - LoopUnrollResult::Unmodified; + bool Changed = + tryToUnrollLoop(&L, AR.DT, &AR.LI, AR.SE, AR.TTI, AR.AC, ORE, + /*BFI*/ nullptr, /*PSI*/ nullptr, + /*PreserveLCSSA*/ true, OptLevel, OnlyWhenForced, + ForgetSCEV, /*Count*/ std::nullopt, + /*Threshold*/ std::nullopt, /*AllowPartial*/ false, + /*Runtime*/ false, /*UpperBound*/ false, + /*AllowPeeling*/ true, + /*AllowProfileBasedPeeling*/ false, + /*FullUnrollMaxCount*/ std::nullopt) != + LoopUnrollResult::Unmodified; if (!Changed) return PreservedAnalyses::all(); @@ -1618,9 +1621,9 @@ PreservedAnalyses LoopUnrollPass::run(Function &F, LoopUnrollResult Result = tryToUnrollLoop( &L, DT, &LI, SE, TTI, AC, ORE, BFI, PSI, /*PreserveLCSSA*/ true, UnrollOpts.OptLevel, UnrollOpts.OnlyWhenForced, - UnrollOpts.ForgetSCEV, /*Count*/ None, - /*Threshold*/ None, UnrollOpts.AllowPartial, UnrollOpts.AllowRuntime, - UnrollOpts.AllowUpperBound, LocalAllowPeeling, + UnrollOpts.ForgetSCEV, /*Count*/ std::nullopt, + /*Threshold*/ std::nullopt, UnrollOpts.AllowPartial, + UnrollOpts.AllowRuntime, UnrollOpts.AllowUpperBound, LocalAllowPeeling, UnrollOpts.AllowProfileBasedPeeling, UnrollOpts.FullUnrollMaxCount); Changed |= Result != LoopUnrollResult::Unmodified; @@ -1646,18 +1649,18 @@ void LoopUnrollPass::printPipeline( static_cast *>(this)->printPipeline( OS, MapClassName2PassName); OS << "<"; - if (UnrollOpts.AllowPartial != None) + if (UnrollOpts.AllowPartial != std::nullopt) OS << (UnrollOpts.AllowPartial.value() ? "" : "no-") << "partial;"; - if (UnrollOpts.AllowPeeling != None) + if (UnrollOpts.AllowPeeling != std::nullopt) OS << (UnrollOpts.AllowPeeling.value() ? "" : "no-") << "peeling;"; - if (UnrollOpts.AllowRuntime != None) + if (UnrollOpts.AllowRuntime != std::nullopt) OS << (UnrollOpts.AllowRuntime.value() ? "" : "no-") << "runtime;"; - if (UnrollOpts.AllowUpperBound != None) + if (UnrollOpts.AllowUpperBound != std::nullopt) OS << (UnrollOpts.AllowUpperBound.value() ? "" : "no-") << "upperbound;"; - if (UnrollOpts.AllowProfileBasedPeeling != None) + if (UnrollOpts.AllowProfileBasedPeeling != std::nullopt) OS << (UnrollOpts.AllowProfileBasedPeeling.value() ? "" : "no-") << "profile-peeling;"; - if (UnrollOpts.FullUnrollMaxCount != None) + if (UnrollOpts.FullUnrollMaxCount != std::nullopt) OS << "full-unroll-max=" << UnrollOpts.FullUnrollMaxCount << ";"; OS << "O" << UnrollOpts.OptLevel; OS << ">"; diff --git a/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp b/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp index e9e7e0a..f06f5cf 100644 --- a/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp +++ b/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp @@ -590,7 +590,7 @@ bool MemCpyOptPass::moveUp(StoreInst *SI, Instruction *P, const LoadInst *LI) { if (!isGuaranteedToTransferExecutionToSuccessor(C)) return false; - bool MayAlias = isModOrRefSet(AA->getModRefInfo(C, None)); + bool MayAlias = isModOrRefSet(AA->getModRefInfo(C, std::nullopt)); bool NeedLift = false; if (Args.erase(C)) diff --git a/llvm/lib/Transforms/Scalar/MergeICmps.cpp b/llvm/lib/Transforms/Scalar/MergeICmps.cpp index 673c40c..0c09c0c 100644 --- a/llvm/lib/Transforms/Scalar/MergeICmps.cpp +++ b/llvm/lib/Transforms/Scalar/MergeICmps.cpp @@ -310,19 +310,19 @@ Optional visitICmp(const ICmpInst *const CmpI, // other comparisons as we would create an orphan use of the value. if (!CmpI->hasOneUse()) { LLVM_DEBUG(dbgs() << "cmp has several uses\n"); - return None; + return std::nullopt; } if (CmpI->getPredicate() != ExpectedPredicate) - return None; + return std::nullopt; LLVM_DEBUG(dbgs() << "cmp " << (ExpectedPredicate == ICmpInst::ICMP_EQ ? "eq" : "ne") << "\n"); auto Lhs = visitICmpLoadOperand(CmpI->getOperand(0), BaseId); if (!Lhs.BaseId) - return None; + return std::nullopt; auto Rhs = visitICmpLoadOperand(CmpI->getOperand(1), BaseId); if (!Rhs.BaseId) - return None; + return std::nullopt; const auto &DL = CmpI->getModule()->getDataLayout(); return BCECmp(std::move(Lhs), std::move(Rhs), DL.getTypeSizeInBits(CmpI->getOperand(0)->getType()), CmpI); @@ -333,9 +333,11 @@ Optional visitICmp(const ICmpInst *const CmpI, Optional visitCmpBlock(Value *const Val, BasicBlock *const Block, const BasicBlock *const PhiBlock, BaseIdentifier &BaseId) { - if (Block->empty()) return None; + if (Block->empty()) + return std::nullopt; auto *const BranchI = dyn_cast(Block->getTerminator()); - if (!BranchI) return None; + if (!BranchI) + return std::nullopt; LLVM_DEBUG(dbgs() << "branch\n"); Value *Cond; ICmpInst::Predicate ExpectedPredicate; @@ -351,7 +353,8 @@ Optional visitCmpBlock(Value *const Val, BasicBlock *const Block, // chained). const auto *const Const = cast(Val); LLVM_DEBUG(dbgs() << "const\n"); - if (!Const->isZero()) return None; + if (!Const->isZero()) + return std::nullopt; LLVM_DEBUG(dbgs() << "false\n"); assert(BranchI->getNumSuccessors() == 2 && "expecting a cond branch"); BasicBlock *const FalseBlock = BranchI->getSuccessor(1); @@ -361,12 +364,13 @@ Optional visitCmpBlock(Value *const Val, BasicBlock *const Block, } auto *CmpI = dyn_cast(Cond); - if (!CmpI) return None; + if (!CmpI) + return std::nullopt; LLVM_DEBUG(dbgs() << "icmp\n"); Optional Result = visitICmp(CmpI, ExpectedPredicate, BaseId); if (!Result) - return None; + return std::nullopt; BCECmpBlock::InstructionSet BlockInsts( {Result->Lhs.LoadI, Result->Rhs.LoadI, Result->CmpI, BranchI}); diff --git a/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp b/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp index 12fd2e6..1ce0b95 100644 --- a/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp +++ b/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp @@ -301,7 +301,7 @@ static ArrayRef GetDeoptBundleOperands(const CallBase *Call) { if (!DeoptBundle) { assert(AllowStatepointWithNoDeoptInfo && "Found non-leaf call without deopt info!"); - return None; + return std::nullopt; } return DeoptBundle->Inputs; diff --git a/llvm/lib/Transforms/Scalar/Scalarizer.cpp b/llvm/lib/Transforms/Scalar/Scalarizer.cpp index bfbe5ae..0316a14 100644 --- a/llvm/lib/Transforms/Scalar/Scalarizer.cpp +++ b/llvm/lib/Transforms/Scalar/Scalarizer.cpp @@ -489,11 +489,11 @@ ScalarizerVisitor::getVectorLayout(Type *Ty, Align Alignment, // Make sure we're dealing with a vector. Layout.VecTy = dyn_cast(Ty); if (!Layout.VecTy) - return None; + return std::nullopt; // Check that we're dealing with full-byte elements. Layout.ElemTy = Layout.VecTy->getElementType(); if (!DL.typeSizeEqualsStoreSize(Layout.ElemTy)) - return None; + return std::nullopt; Layout.VecAlign = Alignment; Layout.ElemSize = DL.getTypeStoreSize(Layout.ElemTy); return Layout; diff --git a/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp b/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp index 399aa63..e3b3d5e 100644 --- a/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp +++ b/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp @@ -124,8 +124,8 @@ struct NonTrivialUnswitchCandidate { TinyPtrVector Invariants; Optional Cost; NonTrivialUnswitchCandidate(Instruction *TI, ArrayRef Invariants, - Optional Cost = None) - : TI(TI), Invariants(Invariants), Cost(Cost) {}; + Optional Cost = std::nullopt) + : TI(TI), Invariants(Invariants), Cost(Cost){}; }; } // end anonymous namespace. diff --git a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp index 2d9288b..c03fbe9 100644 --- a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp +++ b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp @@ -427,7 +427,7 @@ static bool removeRedundantDbgInstrsUsingForwardScan(BasicBlock *BB) { VariableMap; for (auto &I : *BB) { if (DbgValueInst *DVI = dyn_cast(&I)) { - DebugVariable Key(DVI->getVariable(), None, + DebugVariable Key(DVI->getVariable(), std::nullopt, DVI->getDebugLoc()->getInlinedAt()); auto VMI = VariableMap.find(Key); auto *DAI = dyn_cast(DVI); @@ -488,7 +488,7 @@ static bool remomveUndefDbgAssignsFromEntryBlock(BasicBlock *BB) { DenseSet SeenDefForAggregate; // Returns the DebugVariable for DVI with no fragment info. auto GetAggregateVariable = [](DbgValueInst *DVI) { - return DebugVariable(DVI->getVariable(), None, + return DebugVariable(DVI->getVariable(), std::nullopt, DVI->getDebugLoc()->getInlinedAt()); }; diff --git a/llvm/lib/Transforms/Utils/BypassSlowDivision.cpp b/llvm/lib/Transforms/Utils/BypassSlowDivision.cpp index bd7a7f1..5a9dd4a 100644 --- a/llvm/lib/Transforms/Utils/BypassSlowDivision.cpp +++ b/llvm/lib/Transforms/Utils/BypassSlowDivision.cpp @@ -357,12 +357,12 @@ Optional FastDivInsertionTask::insertFastDivAndRem() { VisitedSetTy SetL; ValueRange DividendRange = getValueRange(Dividend, SetL); if (DividendRange == VALRNG_LIKELY_LONG) - return None; + return std::nullopt; VisitedSetTy SetR; ValueRange DivisorRange = getValueRange(Divisor, SetR); if (DivisorRange == VALRNG_LIKELY_LONG) - return None; + return std::nullopt; bool DividendShort = (DividendRange == VALRNG_KNOWN_SHORT); bool DivisorShort = (DivisorRange == VALRNG_KNOWN_SHORT); @@ -387,7 +387,7 @@ Optional FastDivInsertionTask::insertFastDivAndRem() { // If the divisor is not a constant, DAGCombiner will convert it to a // multiplication by a magic constant. It isn't clear if it is worth // introducing control flow to get a narrower multiply. - return None; + return std::nullopt; } // After Constant Hoisting pass, long constants may be represented as @@ -397,7 +397,7 @@ Optional FastDivInsertionTask::insertFastDivAndRem() { if (auto *BCI = dyn_cast(Divisor)) if (BCI->getParent() == SlowDivOrRem->getParent() && isa(BCI->getOperand(0))) - return None; + return std::nullopt; IRBuilder<> Builder(MainBB, MainBB->end()); Builder.SetCurrentDebugLocation(SlowDivOrRem->getDebugLoc()); diff --git a/llvm/lib/Transforms/Utils/CodeExtractor.cpp b/llvm/lib/Transforms/Utils/CodeExtractor.cpp index fba9dbb..9a38f92 100644 --- a/llvm/lib/Transforms/Utils/CodeExtractor.cpp +++ b/llvm/lib/Transforms/Utils/CodeExtractor.cpp @@ -1539,7 +1539,8 @@ static void fixupDebugInfoPostExtraction(Function &OldFunc, Function &NewFunc, assert(OldSP->getUnit() && "Missing compile unit for subprogram"); DIBuilder DIB(*OldFunc.getParent(), /*AllowUnresolved=*/false, OldSP->getUnit()); - auto SPType = DIB.createSubroutineType(DIB.getOrCreateTypeArray(None)); + auto SPType = + DIB.createSubroutineType(DIB.getOrCreateTypeArray(std::nullopt)); DISubprogram::DISPFlags SPFlags = DISubprogram::SPFlagDefinition | DISubprogram::SPFlagOptimized | DISubprogram::SPFlagLocalToUnit; diff --git a/llvm/lib/Transforms/Utils/CodeMoverUtils.cpp b/llvm/lib/Transforms/Utils/CodeMoverUtils.cpp index 768e216..53d09ad 100644 --- a/llvm/lib/Transforms/Utils/CodeMoverUtils.cpp +++ b/llvm/lib/Transforms/Utils/CodeMoverUtils.cpp @@ -129,7 +129,7 @@ const Optional ControlConditions::collectControlConditions( // Limitation: can only handle branch instruction currently. const BranchInst *BI = dyn_cast(IDom->getTerminator()); if (!BI) - return None; + return std::nullopt; bool Inserted = false; if (PDT.dominates(CurBlock, IDom)) { @@ -149,13 +149,13 @@ const Optional ControlConditions::collectControlConditions( Inserted = Conditions.addControlCondition( ControlCondition(BI->getCondition(), false)); } else - return None; + return std::nullopt; if (Inserted) ++NumConditions; if (MaxLookup != 0 && NumConditions > MaxLookup) - return None; + return std::nullopt; CurBlock = IDom; } while (CurBlock != &Dominator); @@ -252,13 +252,13 @@ bool llvm::isControlFlowEquivalent(const BasicBlock &BB0, const BasicBlock &BB1, const Optional BB0Conditions = ControlConditions::collectControlConditions(BB0, *CommonDominator, DT, PDT); - if (BB0Conditions == None) + if (BB0Conditions == std::nullopt) return false; const Optional BB1Conditions = ControlConditions::collectControlConditions(BB1, *CommonDominator, DT, PDT); - if (BB1Conditions == None) + if (BB1Conditions == std::nullopt) return false; return BB0Conditions->isEquivalent(*BB1Conditions); diff --git a/llvm/lib/Transforms/Utils/Debugify.cpp b/llvm/lib/Transforms/Utils/Debugify.cpp index 74ead37..d814c5e 100644 --- a/llvm/lib/Transforms/Utils/Debugify.cpp +++ b/llvm/lib/Transforms/Utils/Debugify.cpp @@ -114,7 +114,8 @@ bool llvm::applyDebugifyMetadata( continue; bool InsertedDbgVal = false; - auto SPType = DIB.createSubroutineType(DIB.getOrCreateTypeArray(None)); + auto SPType = + DIB.createSubroutineType(DIB.getOrCreateTypeArray(std::nullopt)); DISubprogram::DISPFlags SPFlags = DISubprogram::SPFlagDefinition | DISubprogram::SPFlagOptimized; if (F.hasPrivateLinkage() || F.hasInternalLinkage()) diff --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp index af2ae79..a46e469 100644 --- a/llvm/lib/Transforms/Utils/InlineFunction.cpp +++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp @@ -1083,7 +1083,7 @@ void ScopedAliasMetadataDeepCloner::clone() { SmallVector DummyNodes; for (const MDNode *I : MD) { - DummyNodes.push_back(MDTuple::getTemporary(I->getContext(), None)); + DummyNodes.push_back(MDTuple::getTemporary(I->getContext(), std::nullopt)); MDMap[I].reset(DummyNodes.back().get()); } @@ -1896,7 +1896,8 @@ static void updateCallProfile(Function *Callee, const ValueToValueMapTy &VMap, BlockFrequencyInfo *CallerBFI) { if (CalleeEntryCount.isSynthetic() || CalleeEntryCount.getCount() < 1) return; - auto CallSiteCount = PSI ? PSI->getProfileCount(TheCall, CallerBFI) : None; + auto CallSiteCount = + PSI ? PSI->getProfileCount(TheCall, CallerBFI) : std::nullopt; int64_t CallCount = std::min(CallSiteCount.value_or(0), CalleeEntryCount.getCount()); updateProfileCallee(Callee, -CallCount, &VMap); diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp index c9fe093..d4d061a 100644 --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -2174,7 +2174,7 @@ bool llvm::replaceAllDbgUsesWith(Instruction &From, Value &To, // Without knowing signedness, sign/zero extension isn't possible. auto Signedness = Var->getSignedness(); if (!Signedness) - return None; + return std::nullopt; bool Signed = *Signedness == DIBasicType::Signedness::Signed; return DIExpression::appendExt(DII.getExpression(), ToBits, FromBits, @@ -2912,7 +2912,7 @@ void llvm::copyRangeMetadata(const DataLayout &DL, const LoadInst &OldLI, unsigned BitWidth = DL.getPointerTypeSizeInBits(NewTy); if (!getConstantRangeFromMetadata(*N).contains(APInt(BitWidth, 0))) { - MDNode *NN = MDNode::get(OldLI.getContext(), None); + MDNode *NN = MDNode::get(OldLI.getContext(), std::nullopt); NewLI.setMetadata(LLVMContext::MD_nonnull, NN); } } @@ -3021,7 +3021,7 @@ collectBitParts(Value *V, bool MatchBSwaps, bool MatchBitReversals, if (I != BPS.end()) return I->second; - auto &Result = BPS[V] = None; + auto &Result = BPS[V] = std::nullopt; auto BitWidth = V->getType()->getScalarSizeInBits(); // Can't do integer/elements > 128 bits. @@ -3057,7 +3057,7 @@ collectBitParts(Value *V, bool MatchBSwaps, bool MatchBitReversals, if (A->Provenance[BitIdx] != BitPart::Unset && B->Provenance[BitIdx] != BitPart::Unset && A->Provenance[BitIdx] != B->Provenance[BitIdx]) - return Result = None; + return Result = std::nullopt; if (A->Provenance[BitIdx] == BitPart::Unset) Result->Provenance[BitIdx] = B->Provenance[BitIdx]; diff --git a/llvm/lib/Transforms/Utils/LoopPeel.cpp b/llvm/lib/Transforms/Utils/LoopPeel.cpp index e870409..bfb865a 100644 --- a/llvm/lib/Transforms/Utils/LoopPeel.cpp +++ b/llvm/lib/Transforms/Utils/LoopPeel.cpp @@ -165,7 +165,7 @@ public: protected: using PeelCounter = std::optional; - const PeelCounter Unknown = None; + const PeelCounter Unknown = std::nullopt; // Add 1 respecting Unknown and return Unknown if result over MaxIterations PeelCounter addOne(PeelCounter PC) const { @@ -250,7 +250,7 @@ Optional PhiAnalyzer::calculateIterationsToPeel() { } } assert((Iterations <= MaxIterations) && "bad result in phi analysis"); - return Iterations ? Optional(Iterations) : None; + return Iterations ? Optional(Iterations) : std::nullopt; } } // unnamed namespace diff --git a/llvm/lib/Transforms/Utils/LoopUnroll.cpp b/llvm/lib/Transforms/Utils/LoopUnroll.cpp index bc3a30a..da8d375 100644 --- a/llvm/lib/Transforms/Utils/LoopUnroll.cpp +++ b/llvm/lib/Transforms/Utils/LoopUnroll.cpp @@ -703,7 +703,7 @@ LoopUnrollResult llvm::UnrollLoop(Loop *L, UnrollLoopOptions ULO, LoopInfo *LI, if (CompletelyUnroll) { if (PreserveOnlyFirst) { if (i == 0) - return None; + return std::nullopt; return j == 0; } // Complete (but possibly inexact) unrolling @@ -711,7 +711,7 @@ LoopUnrollResult llvm::UnrollLoop(Loop *L, UnrollLoopOptions ULO, LoopInfo *LI, return true; if (Info.TripCount && j != Info.TripCount) return false; - return None; + return std::nullopt; } if (ULO.Runtime) { @@ -719,7 +719,7 @@ LoopUnrollResult llvm::UnrollLoop(Loop *L, UnrollLoopOptions ULO, LoopInfo *LI, // exits may be stale. if (IsLatch && j != 0) return false; - return None; + return std::nullopt; } if (j != Info.BreakoutTrip && @@ -728,7 +728,7 @@ LoopUnrollResult llvm::UnrollLoop(Loop *L, UnrollLoopOptions ULO, LoopInfo *LI, // unconditional branch for some iterations. return false; } - return None; + return std::nullopt; }; // Fold branches for iterations where we know that they will exit or not diff --git a/llvm/lib/Transforms/Utils/LoopUtils.cpp b/llvm/lib/Transforms/Utils/LoopUtils.cpp index b69735a..9ada3a2 100644 --- a/llvm/lib/Transforms/Utils/LoopUtils.cpp +++ b/llvm/lib/Transforms/Utils/LoopUtils.cpp @@ -258,7 +258,7 @@ llvm::getOptionalElementCountLoopAttribute(const Loop *TheLoop) { return ElementCount::get(*Width, IsScalable.value_or(false)); } - return None; + return std::nullopt; } Optional llvm::makeFollowupLoopID( @@ -267,7 +267,7 @@ Optional llvm::makeFollowupLoopID( if (!OrigLoopID) { if (AlwaysNew) return nullptr; - return None; + return std::nullopt; } assert(OrigLoopID->getOperand(0) == OrigLoopID); @@ -326,7 +326,7 @@ Optional llvm::makeFollowupLoopID( // Attributes of the followup loop not specified explicity, so signal to the // transformation pass to add suitable attributes. if (!AlwaysNew && !HasAnyFollowup) - return None; + return std::nullopt; // If no attributes were added or remove, the previous loop Id can be reused. if (!AlwaysNew && !Changed) @@ -790,14 +790,14 @@ getEstimatedTripCount(BranchInst *ExitingBranch, Loop *L, // we exited the loop. uint64_t LoopWeight, ExitWeight; if (!extractBranchWeights(*ExitingBranch, LoopWeight, ExitWeight)) - return None; + return std::nullopt; if (L->contains(ExitingBranch->getSuccessor(1))) std::swap(LoopWeight, ExitWeight); if (!ExitWeight) // Don't have a way to return predicated infinite - return None; + return std::nullopt; OrigExitWeight = ExitWeight; @@ -824,7 +824,7 @@ llvm::getLoopEstimatedTripCount(Loop *L, return *EstTripCount; } } - return None; + return std::nullopt; } bool llvm::setLoopEstimatedTripCount(Loop *L, unsigned EstimatedTripCount, diff --git a/llvm/lib/Transforms/Utils/MemoryOpRemark.cpp b/llvm/lib/Transforms/Utils/MemoryOpRemark.cpp index 68d4dd9..dbef880 100644 --- a/llvm/lib/Transforms/Utils/MemoryOpRemark.cpp +++ b/llvm/lib/Transforms/Utils/MemoryOpRemark.cpp @@ -146,7 +146,7 @@ static void inlineVolatileOrAtomicWithExtraArgs(bool *Inline, bool Volatile, static Optional getSizeInBytes(Optional SizeInBits) { if (!SizeInBits || *SizeInBits % 8 != 0) - return None; + return std::nullopt; return *SizeInBits / 8; } @@ -300,7 +300,7 @@ void MemoryOpRemark::visitSizeOperand(Value *V, DiagnosticInfoIROptimization &R) static Optional nameOrNone(const Value *V) { if (V->hasName()) return V->getName(); - return None; + return std::nullopt; } void MemoryOpRemark::visitVariable(const Value *V, @@ -341,7 +341,7 @@ void MemoryOpRemark::visitVariable(const Value *V, // If not, get it from the alloca. Optional TySize = AI->getAllocationSizeInBits(DL); Optional Size = - TySize ? getSizeInBytes(TySize->getFixedSize()) : None; + TySize ? getSizeInBytes(TySize->getFixedSize()) : std::nullopt; VariableInfo Var{nameOrNone(AI), Size}; if (!Var.isEmpty()) Result.push_back(std::move(Var)); @@ -361,7 +361,7 @@ void MemoryOpRemark::visitPtr(Value *Ptr, bool IsRead, DiagnosticInfoIROptimizat uint64_t Size = Ptr->getPointerDereferenceableBytes(DL, CanBeNull, CanBeFreed); if (!Size) return; - VIs.push_back({None, Size}); + VIs.push_back({std::nullopt, Size}); } R << (IsRead ? "\n Read Variables: " : "\n Written Variables: "); diff --git a/llvm/lib/Transforms/Utils/PredicateInfo.cpp b/llvm/lib/Transforms/Utils/PredicateInfo.cpp index 92bbbe6..9a1f334 100644 --- a/llvm/lib/Transforms/Utils/PredicateInfo.cpp +++ b/llvm/lib/Transforms/Utils/PredicateInfo.cpp @@ -800,7 +800,7 @@ Optional PredicateBase::getConstraint() const { CmpInst *Cmp = dyn_cast(Condition); if (!Cmp) { // TODO: Make this an assertion once RenamedOp is fully accurate. - return None; + return std::nullopt; } CmpInst::Predicate Pred; @@ -813,7 +813,7 @@ Optional PredicateBase::getConstraint() const { OtherOp = Cmp->getOperand(0); } else { // TODO: Make this an assertion once RenamedOp is fully accurate. - return None; + return std::nullopt; } // Invert predicate along false edge. @@ -825,7 +825,7 @@ Optional PredicateBase::getConstraint() const { case PT_Switch: if (Condition != RenamedOp) { // TODO: Make this an assertion once RenamedOp is fully accurate. - return None; + return std::nullopt; } return {{CmpInst::ICMP_EQ, cast(this)->CaseValue}}; diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp index 62f0791..6cdd18f 100644 --- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp @@ -3267,7 +3267,7 @@ FoldCondBranchOnValueKnownInPredecessorImpl(BranchInst *BI, DomTreeUpdater *DTU, MergeBlockIntoPredecessor(EdgeBB, DTU); // Signal repeat, simplifying any other constants. - return None; + return std::nullopt; } return false; @@ -3282,8 +3282,8 @@ static bool FoldCondBranchOnValueKnownInPredecessor(BranchInst *BI, do { // Note that None means "we changed things, but recurse further." Result = FoldCondBranchOnValueKnownInPredecessorImpl(BI, DTU, DL, AC); - EverChanged |= Result == None || *Result; - } while (Result == None); + EverChanged |= Result == std::nullopt || *Result; + } while (Result == std::nullopt); return EverChanged; } @@ -3558,7 +3558,7 @@ shouldFoldCondBranchesToCommonDestination(BranchInst *BI, BranchInst *PBI, if (PBITrueProb.isUnknown() || PBITrueProb.getCompl() < Likely) return {{Instruction::Or, true}}; } - return None; + return std::nullopt; } static bool performBranchToCommonDestFolding(BranchInst *BI, BranchInst *PBI, diff --git a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp index db7a6d5..84adb6a 100644 --- a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp @@ -1042,9 +1042,8 @@ class WidenIV { Instruction *UseI) { DefUserPair Key(Def, UseI); auto It = PostIncRangeInfos.find(Key); - return It == PostIncRangeInfos.end() - ? Optional(None) - : Optional(It->second); + return It == PostIncRangeInfos.end() ? Optional(std::nullopt) + : Optional(It->second); } void calculatePostIncRanges(PHINode *OrigPhi); diff --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp index 9b5d0b8f..061ddd7 100644 --- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp @@ -3855,7 +3855,7 @@ Value *FortifiedLibCallSimplifier::optimizeStrpCpyChk(CallInst *CI, // st[rp]cpy_chk call which may fail at runtime if the size is too long. // TODO: It might be nice to get a maximum length out of the possible // string lengths for varying. - if (isFortifiedCallFoldable(CI, 2, None, 1)) { + if (isFortifiedCallFoldable(CI, 2, std::nullopt, 1)) { if (Func == LibFunc_strcpy_chk) return copyFlags(*CI, emitStrCpy(Dst, Src, B, TLI)); else @@ -3886,7 +3886,7 @@ Value *FortifiedLibCallSimplifier::optimizeStrpCpyChk(CallInst *CI, Value *FortifiedLibCallSimplifier::optimizeStrLenChk(CallInst *CI, IRBuilderBase &B) { - if (isFortifiedCallFoldable(CI, 1, None, 0)) + if (isFortifiedCallFoldable(CI, 1, std::nullopt, 0)) return copyFlags(*CI, emitStrLen(CI->getArgOperand(0), B, CI->getModule()->getDataLayout(), TLI)); return nullptr; @@ -3921,7 +3921,7 @@ Value *FortifiedLibCallSimplifier::optimizeMemCCpyChk(CallInst *CI, Value *FortifiedLibCallSimplifier::optimizeSNPrintfChk(CallInst *CI, IRBuilderBase &B) { - if (isFortifiedCallFoldable(CI, 3, 1, None, 2)) { + if (isFortifiedCallFoldable(CI, 3, 1, std::nullopt, 2)) { SmallVector VariadicArgs(drop_begin(CI->args(), 5)); return copyFlags(*CI, emitSNPrintf(CI->getArgOperand(0), CI->getArgOperand(1), @@ -3933,7 +3933,7 @@ Value *FortifiedLibCallSimplifier::optimizeSNPrintfChk(CallInst *CI, Value *FortifiedLibCallSimplifier::optimizeSPrintfChk(CallInst *CI, IRBuilderBase &B) { - if (isFortifiedCallFoldable(CI, 2, None, None, 1)) { + if (isFortifiedCallFoldable(CI, 2, std::nullopt, std::nullopt, 1)) { SmallVector VariadicArgs(drop_begin(CI->args(), 4)); return copyFlags(*CI, emitSPrintf(CI->getArgOperand(0), CI->getArgOperand(3), @@ -3984,7 +3984,7 @@ Value *FortifiedLibCallSimplifier::optimizeStrLCpyChk(CallInst *CI, Value *FortifiedLibCallSimplifier::optimizeVSNPrintfChk(CallInst *CI, IRBuilderBase &B) { - if (isFortifiedCallFoldable(CI, 3, 1, None, 2)) + if (isFortifiedCallFoldable(CI, 3, 1, std::nullopt, 2)) return copyFlags( *CI, emitVSNPrintf(CI->getArgOperand(0), CI->getArgOperand(1), CI->getArgOperand(4), CI->getArgOperand(5), B, TLI)); @@ -3994,7 +3994,7 @@ Value *FortifiedLibCallSimplifier::optimizeVSNPrintfChk(CallInst *CI, Value *FortifiedLibCallSimplifier::optimizeVSPrintfChk(CallInst *CI, IRBuilderBase &B) { - if (isFortifiedCallFoldable(CI, 2, None, None, 1)) + if (isFortifiedCallFoldable(CI, 2, std::nullopt, std::nullopt, 1)) return copyFlags(*CI, emitVSPrintf(CI->getArgOperand(0), CI->getArgOperand(3), CI->getArgOperand(4), B, TLI)); diff --git a/llvm/lib/Transforms/Utils/ValueMapper.cpp b/llvm/lib/Transforms/Utils/ValueMapper.cpp index 8947303..3d9fd56 100644 --- a/llvm/lib/Transforms/Utils/ValueMapper.cpp +++ b/llvm/lib/Transforms/Utils/ValueMapper.cpp @@ -391,8 +391,9 @@ Value *Mapper::mapValue(const Value *V) { // ensures metadata operands only reference defined SSA values. return (Flags & RF_IgnoreMissingLocals) ? nullptr - : MetadataAsValue::get(V->getContext(), - MDTuple::get(V->getContext(), None)); + : MetadataAsValue::get( + V->getContext(), + MDTuple::get(V->getContext(), std::nullopt)); } if (auto *AL = dyn_cast(MD)) { SmallVector MappedArgs; @@ -578,7 +579,7 @@ Optional MDNodeMapper::tryToMapOperand(const Metadata *Op) { const MDNode &N = *cast(Op); if (N.isDistinct()) return mapDistinctNode(N); - return None; + return std::nullopt; } MDNode *MDNodeMapper::mapDistinctNode(const MDNode &N) { @@ -619,7 +620,7 @@ Optional MDNodeMapper::getMappedOp(const Metadata *Op) const { if (auto *CMD = dyn_cast(Op)) return wrapConstantAsMetadata(*CMD, M.getVM().lookup(CMD->getValue())); - return None; + return std::nullopt; } Metadata &MDNodeMapper::UniquedGraph::getFwdReference(MDNode &Op) { @@ -848,7 +849,7 @@ Optional Mapper::mapSimpleMetadata(const Metadata *MD) { assert(isa(MD) && "Expected a metadata node"); - return None; + return std::nullopt; } Metadata *Mapper::mapMetadata(const Metadata *MD) { diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 5f4bb54..051eb99 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -417,7 +417,7 @@ static Optional getSmallBestKnownTC(ScalarEvolution &SE, Loop *L) { if (unsigned ExpectedTC = SE.getSmallConstantMaxTripCount(L)) return ExpectedTC; - return None; + return std::nullopt; } // Forward declare GeneratedRTChecks. @@ -6452,8 +6452,8 @@ LoopVectorizationCostModel::getConsecutiveMemOpCost(Instruction *I, bool Reverse = ConsecutiveStride < 0; if (Reverse) - Cost += TTI.getShuffleCost(TargetTransformInfo::SK_Reverse, VectorTy, None, - CostKind, 0); + Cost += TTI.getShuffleCost(TargetTransformInfo::SK_Reverse, VectorTy, + std::nullopt, CostKind, 0); return Cost; } @@ -6537,8 +6537,8 @@ LoopVectorizationCostModel::getInterleaveGroupCost(Instruction *I, assert(!Legal->isMaskRequired(I) && "Reverse masked interleaved access not supported."); Cost += Group->getNumMembers() * - TTI.getShuffleCost(TargetTransformInfo::SK_Reverse, VectorTy, None, - CostKind, 0); + TTI.getShuffleCost(TargetTransformInfo::SK_Reverse, VectorTy, + std::nullopt, CostKind, 0); } return Cost; } @@ -6548,7 +6548,7 @@ Optional LoopVectorizationCostModel::getReductionPatternCost( using namespace llvm::PatternMatch; // Early exit for no inloop reductions if (InLoopReductionChains.empty() || VF.isScalar() || !isa(Ty)) - return None; + return std::nullopt; auto *VectorTy = cast(Ty); // We are looking for a pattern of, and finding the minimal acceptable cost: @@ -6566,7 +6566,7 @@ Optional LoopVectorizationCostModel::getReductionPatternCost( Instruction *RetI = I; if (match(RetI, m_ZExtOrSExt(m_Value()))) { if (!RetI->hasOneUser()) - return None; + return std::nullopt; RetI = RetI->user_back(); } @@ -6578,7 +6578,7 @@ Optional LoopVectorizationCostModel::getReductionPatternCost( // Test if the found instruction is a reduction, and if not return an invalid // cost specifying the parent to use the original cost modelling. if (!InLoopReductionImmediateChains.count(RetI)) - return None; + return std::nullopt; // Find the reduction this chain is a part of and calculate the basic cost of // the reduction on its own. @@ -6712,7 +6712,7 @@ Optional LoopVectorizationCostModel::getReductionPatternCost( } } - return I == RetI ? Optional(BaseCost) : None; + return I == RetI ? Optional(BaseCost) : std::nullopt; } InstructionCost @@ -7498,7 +7498,7 @@ LoopVectorizationPlanner::plan(ElementCount UserVF, unsigned UserIC) { assert(OrigLoop->isInnermost() && "Inner loop expected."); FixedScalableVFPair MaxFactors = CM.computeMaxVF(UserVF, UserIC); if (!MaxFactors) // Cases that should not to be vectorized nor interleaved. - return None; + return std::nullopt; // Invalidate interleave groups if all blocks of loop will be predicated. if (CM.blockNeedsPredicationForAnyReason(OrigLoop->getHeader()) && diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 1311c12..ea3fac8 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -293,12 +293,12 @@ static Optional getInsertIndex(const Value *InsertInst, if (const auto *IE = dyn_cast(InsertInst)) { const auto *VT = dyn_cast(IE->getType()); if (!VT) - return None; + return std::nullopt; const auto *CI = dyn_cast(IE->getOperand(2)); if (!CI) - return None; + return std::nullopt; if (CI->getValue().uge(VT->getNumElements())) - return None; + return std::nullopt; Index *= VT->getNumElements(); Index += CI->getZExtValue(); return Index; @@ -314,7 +314,7 @@ static Optional getInsertIndex(const Value *InsertInst, Index *= AT->getNumElements(); CurrentType = AT->getElementType(); } else { - return None; + return std::nullopt; } Index += I; } @@ -326,7 +326,7 @@ static Optional getInsertIndex(const Value *InsertInst, /// elements actually mask the insertelement buildvector, if any. template static SmallBitVector isUndefVector(const Value *V, - ArrayRef ShuffleMask = None) { + ArrayRef ShuffleMask = std::nullopt) { SmallBitVector Res(ShuffleMask.empty() ? 1 : ShuffleMask.size(), true); using T = std::conditional_t; if (isa(V)) @@ -417,10 +417,10 @@ isFixedVectorShuffle(ArrayRef VL, SmallVectorImpl &Mask) { const auto *It = find_if(VL, [](Value *V) { return isa(V); }); if (It == VL.end()) - return None; + return std::nullopt; auto *EI0 = cast(*It); if (isa(EI0->getVectorOperandType())) - return None; + return std::nullopt; unsigned Size = cast(EI0->getVectorOperandType())->getNumElements(); Value *Vec1 = nullptr; @@ -434,19 +434,19 @@ isFixedVectorShuffle(ArrayRef VL, SmallVectorImpl &Mask) { continue; auto *EI = cast(VL[I]); if (isa(EI->getVectorOperandType())) - return None; + return std::nullopt; auto *Vec = EI->getVectorOperand(); // We can extractelement from undef or poison vector. if (isUndefVector(Vec).all()) continue; // All vector operands must have the same number of vector elements. if (cast(Vec->getType())->getNumElements() != Size) - return None; + return std::nullopt; if (isa(EI->getIndexOperand())) continue; auto *Idx = dyn_cast(EI->getIndexOperand()); if (!Idx) - return None; + return std::nullopt; // Undefined behavior if Idx is negative or >= Size. if (Idx->getValue().uge(Size)) continue; @@ -460,7 +460,7 @@ isFixedVectorShuffle(ArrayRef VL, SmallVectorImpl &Mask) { Vec2 = Vec; Mask[I] += Size; } else { - return None; + return std::nullopt; } if (CommonShuffleMode == Permute) continue; @@ -737,12 +737,12 @@ static Optional getExtractIndex(Instruction *E) { if (Opcode == Instruction::ExtractElement) { auto *CI = dyn_cast(E->getOperand(1)); if (!CI) - return None; + return std::nullopt; return CI->getZExtValue(); } ExtractValueInst *EI = cast(E); if (EI->getNumIndices() != 1) - return None; + return std::nullopt; return *EI->idx_begin(); } @@ -980,7 +980,7 @@ public: /// \returns the vectorization cost of the subtree that starts at \p VL. /// A negative number means that this is profitable. - InstructionCost getTreeCost(ArrayRef VectorizedVals = None); + InstructionCost getTreeCost(ArrayRef VectorizedVals = std::nullopt); /// Construct a vectorizable tree that starts at \p Roots, ignoring users for /// the purpose of scheduling and extraction in the \p UserIgnoreLst. @@ -1420,7 +1420,7 @@ public: // Recursively calculate the cost at each level int TmpScore = getScoreAtLevelRec(I1->getOperand(OpIdx1), I2->getOperand(OpIdx2), - I1, I2, CurrLevel + 1, None); + I1, I2, CurrLevel + 1, std::nullopt); // Look for the best score. if (TmpScore > LookAheadHeuristics::ScoreFail && TmpScore > MaxTmpScore) { @@ -1585,7 +1585,7 @@ public: auto *IdxLaneI = dyn_cast(IdxLaneV); if (!IdxLaneI || !isa(OpIdxLaneV)) return 0; - return R.areAllUsersVectorized(IdxLaneI, None) + return R.areAllUsersVectorized(IdxLaneI, std::nullopt) ? LookAheadHeuristics::ScoreAllUserVectorized : 0; } @@ -1653,7 +1653,7 @@ public: // Our strategy mode for OpIdx. ReorderingMode RMode = ReorderingModes[OpIdx]; if (RMode == ReorderingMode::Failed) - return None; + return std::nullopt; // The linearized opcode of the operand at OpIdx, Lane. bool OpIdxAPO = getData(OpIdx, Lane).APO; @@ -1662,7 +1662,7 @@ public: // Sometimes we have more than one option (e.g., Opcode and Undefs), so we // are using the score to differentiate between the two. struct BestOpData { - Optional Idx = None; + Optional Idx = std::nullopt; unsigned Score = 0; } BestOp; BestOp.Score = @@ -1722,7 +1722,7 @@ public: return BestOp.Idx; } // If we could not find a good match return None. - return None; + return std::nullopt; } /// Helper for reorderOperandVecs. @@ -2153,7 +2153,7 @@ public: int Score = LookAhead.getScoreAtLevelRec(Candidates[I].first, Candidates[I].second, /*U1=*/nullptr, /*U2=*/nullptr, - /*Level=*/1, None); + /*Level=*/1, std::nullopt); if (Score > BestScore) { BestScore = Score; Index = I; @@ -2655,8 +2655,8 @@ private: TreeEntry *newTreeEntry(ArrayRef VL, Optional Bundle, const InstructionsState &S, const EdgeInfo &UserTreeIdx, - ArrayRef ReuseShuffleIndices = None, - ArrayRef ReorderIndices = None) { + ArrayRef ReuseShuffleIndices = std::nullopt, + ArrayRef ReorderIndices = std::nullopt) { TreeEntry::EntryState EntryState = Bundle ? TreeEntry::Vectorize : TreeEntry::NeedToGather; return newTreeEntry(VL, EntryState, Bundle, S, UserTreeIdx, @@ -2668,8 +2668,8 @@ private: Optional Bundle, const InstructionsState &S, const EdgeInfo &UserTreeIdx, - ArrayRef ReuseShuffleIndices = None, - ArrayRef ReorderIndices = None) { + ArrayRef ReuseShuffleIndices = std::nullopt, + ArrayRef ReorderIndices = std::nullopt) { assert(((!Bundle && EntryState == TreeEntry::NeedToGather) || (Bundle && EntryState != TreeEntry::NeedToGather)) && "Need to vectorize gather entry?"); @@ -3580,11 +3580,11 @@ BoUpSLP::findReusedOrderedScalars(const BoUpSLP::TreeEntry &TE) { STE = LocalSTE; else if (STE != LocalSTE) // Take the order only from the single vector node. - return None; + return std::nullopt; unsigned Lane = std::distance(STE->Scalars.begin(), find(STE->Scalars, V)); if (Lane >= NumScalars) - return None; + return std::nullopt; if (CurrentOrder[Lane] != NumScalars) { if (Lane != I) continue; @@ -3623,7 +3623,7 @@ BoUpSLP::findReusedOrderedScalars(const BoUpSLP::TreeEntry &TE) { } return CurrentOrder; } - return None; + return std::nullopt; } namespace { @@ -3808,14 +3808,14 @@ BoUpSLP::findPartiallyOrderedLoads(const BoUpSLP::TreeEntry &TE) { for (Value *V : TE.Scalars) { auto *L = dyn_cast(V); if (!L || !L->isSimple()) - return None; + return std::nullopt; Ptrs.push_back(L->getPointerOperand()); } BoUpSLP::OrdersType Order; if (clusterSortPtrAccesses(Ptrs, ScalarTy, *DL, *SE, Order)) return Order; - return None; + return std::nullopt; } /// Check if two insertelement instructions are from the same buildvector. @@ -3835,7 +3835,7 @@ static bool areTwoInsertFromSameBuildVector( auto *IE2 = V; Optional Idx1 = getInsertIndex(IE1); Optional Idx2 = getInsertIndex(IE2); - if (Idx1 == None || Idx2 == None) + if (Idx1 == std::nullopt || Idx2 == std::nullopt) return false; // Go through the vector operand of insertelement instructions trying to find // either VU as the original vector for IE2 or V as the original vector for @@ -3878,7 +3878,7 @@ Optional BoUpSLP::getReorderingData(const TreeEntry &TE, unsigned Sz = TE.Scalars.size(); if (!ShuffleVectorInst::isOneUseSingleSourceMask(TE.ReuseShuffleIndices, Sz)) - return None; + return std::nullopt; unsigned VF = TE.getVectorFactor(); // Try build correct order for extractelement instructions. SmallVector ReusedMask(TE.ReuseShuffleIndices.begin(), @@ -3940,7 +3940,7 @@ Optional BoUpSLP::getReorderingData(const TreeEntry &TE, return false; Optional Idx1 = getInsertIndex(IE1); Optional Idx2 = getInsertIndex(IE2); - if (Idx1 == None || Idx2 == None) + if (Idx1 == std::nullopt || Idx2 == std::nullopt) return false; return *Idx1 < *Idx2; } @@ -3950,7 +3950,7 @@ Optional BoUpSLP::getReorderingData(const TreeEntry &TE, return false; Optional Idx1 = getExtractIndex(EE1); Optional Idx2 = getExtractIndex(EE2); - if (Idx1 == None || Idx2 == None) + if (Idx1 == std::nullopt || Idx2 == std::nullopt) return false; return *Idx1 < *Idx2; } @@ -4011,7 +4011,7 @@ Optional BoUpSLP::getReorderingData(const TreeEntry &TE, if (Optional Order = findPartiallyOrderedLoads(TE)) return Order; } - return None; + return std::nullopt; } /// Checks if the given mask is a "clustered" mask with the same clusters of @@ -4961,7 +4961,7 @@ void BoUpSLP::buildTree_rec(ArrayRef VL, unsigned Depth, })) || !llvm::isPowerOf2_32(NumUniqueScalarValues)) { LLVM_DEBUG(dbgs() << "SLP: Scalar used twice in bundle.\n"); - newTreeEntry(VL, None /*not vectorized*/, S, UserTreeIdx); + newTreeEntry(VL, std::nullopt /*not vectorized*/, S, UserTreeIdx); return false; } VL = UniqueValues; @@ -4985,7 +4985,7 @@ void BoUpSLP::buildTree_rec(ArrayRef VL, unsigned Depth, })))) { LLVM_DEBUG(dbgs() << "SLP: Gathering due to max recursion depth.\n"); if (TryToFindDuplicates(S)) - newTreeEntry(VL, None /*not vectorized*/, S, UserTreeIdx, + newTreeEntry(VL, std::nullopt /*not vectorized*/, S, UserTreeIdx, ReuseShuffleIndicies); return; } @@ -4996,7 +4996,7 @@ void BoUpSLP::buildTree_rec(ArrayRef VL, unsigned Depth, cast(S.OpValue)->getVectorOperandType())) { LLVM_DEBUG(dbgs() << "SLP: Gathering due to scalable vector type.\n"); if (TryToFindDuplicates(S)) - newTreeEntry(VL, None /*not vectorized*/, S, UserTreeIdx, + newTreeEntry(VL, std::nullopt /*not vectorized*/, S, UserTreeIdx, ReuseShuffleIndicies); return; } @@ -5005,14 +5005,14 @@ void BoUpSLP::buildTree_rec(ArrayRef VL, unsigned Depth, if (S.OpValue->getType()->isVectorTy() && !isa(S.OpValue)) { LLVM_DEBUG(dbgs() << "SLP: Gathering due to vector type.\n"); - newTreeEntry(VL, None /*not vectorized*/, S, UserTreeIdx); + newTreeEntry(VL, std::nullopt /*not vectorized*/, S, UserTreeIdx); return; } if (StoreInst *SI = dyn_cast(S.OpValue)) if (SI->getValueOperand()->getType()->isVectorTy()) { LLVM_DEBUG(dbgs() << "SLP: Gathering due to store vector type.\n"); - newTreeEntry(VL, None /*not vectorized*/, S, UserTreeIdx); + newTreeEntry(VL, std::nullopt /*not vectorized*/, S, UserTreeIdx); return; } @@ -5100,7 +5100,7 @@ void BoUpSLP::buildTree_rec(ArrayRef VL, unsigned Depth, NotProfitableForVectorization(VL)) { LLVM_DEBUG(dbgs() << "SLP: Gathering due to C,S,B,O, small shuffle. \n"); if (TryToFindDuplicates(S)) - newTreeEntry(VL, None /*not vectorized*/, S, UserTreeIdx, + newTreeEntry(VL, std::nullopt /*not vectorized*/, S, UserTreeIdx, ReuseShuffleIndicies); return; } @@ -5114,7 +5114,7 @@ void BoUpSLP::buildTree_rec(ArrayRef VL, unsigned Depth, if (EphValues.count(V)) { LLVM_DEBUG(dbgs() << "SLP: The instruction (" << *V << ") is ephemeral.\n"); - newTreeEntry(VL, None /*not vectorized*/, S, UserTreeIdx); + newTreeEntry(VL, std::nullopt /*not vectorized*/, S, UserTreeIdx); return; } } @@ -5126,7 +5126,7 @@ void BoUpSLP::buildTree_rec(ArrayRef VL, unsigned Depth, if (!E->isSame(VL)) { LLVM_DEBUG(dbgs() << "SLP: Gathering due to partial overlap.\n"); if (TryToFindDuplicates(S)) - newTreeEntry(VL, None /*not vectorized*/, S, UserTreeIdx, + newTreeEntry(VL, std::nullopt /*not vectorized*/, S, UserTreeIdx, ReuseShuffleIndicies); return; } @@ -5146,7 +5146,7 @@ void BoUpSLP::buildTree_rec(ArrayRef VL, unsigned Depth, LLVM_DEBUG(dbgs() << "SLP: The instruction (" << *V << ") is already in tree.\n"); if (TryToFindDuplicates(S)) - newTreeEntry(VL, None /*not vectorized*/, S, UserTreeIdx, + newTreeEntry(VL, std::nullopt /*not vectorized*/, S, UserTreeIdx, ReuseShuffleIndicies); return; } @@ -5158,7 +5158,7 @@ void BoUpSLP::buildTree_rec(ArrayRef VL, unsigned Depth, if (UserIgnoreList && UserIgnoreList->contains(V)) { LLVM_DEBUG(dbgs() << "SLP: Gathering due to gathered scalar.\n"); if (TryToFindDuplicates(S)) - newTreeEntry(VL, None /*not vectorized*/, S, UserTreeIdx, + newTreeEntry(VL, std::nullopt /*not vectorized*/, S, UserTreeIdx, ReuseShuffleIndicies); return; } @@ -5189,7 +5189,7 @@ void BoUpSLP::buildTree_rec(ArrayRef VL, unsigned Depth, // Don't go into unreachable blocks. They may contain instructions with // dependency cycles which confuse the final scheduling. LLVM_DEBUG(dbgs() << "SLP: bundle in unreachable block.\n"); - newTreeEntry(VL, None /*not vectorized*/, S, UserTreeIdx); + newTreeEntry(VL, std::nullopt /*not vectorized*/, S, UserTreeIdx); return; } @@ -5198,7 +5198,7 @@ void BoUpSLP::buildTree_rec(ArrayRef VL, unsigned Depth, // place to insert a shuffle if we need to, so just avoid that issue. if (isa(BB->getTerminator())) { LLVM_DEBUG(dbgs() << "SLP: bundle in catchswitch block.\n"); - newTreeEntry(VL, None /*not vectorized*/, S, UserTreeIdx); + newTreeEntry(VL, std::nullopt /*not vectorized*/, S, UserTreeIdx); return; } @@ -5222,7 +5222,7 @@ void BoUpSLP::buildTree_rec(ArrayRef VL, unsigned Depth, assert((!BS.getScheduleData(VL0) || !BS.getScheduleData(VL0)->isPartOfBundle()) && "tryScheduleBundle should cancelScheduling on failure"); - newTreeEntry(VL, None /*not vectorized*/, S, UserTreeIdx, + newTreeEntry(VL, std::nullopt /*not vectorized*/, S, UserTreeIdx, ReuseShuffleIndicies); return; } @@ -5242,7 +5242,7 @@ void BoUpSLP::buildTree_rec(ArrayRef VL, unsigned Depth, LLVM_DEBUG(dbgs() << "SLP: Need to swizzle PHINodes (terminator use).\n"); BS.cancelScheduling(VL, VL0); - newTreeEntry(VL, None /*not vectorized*/, S, UserTreeIdx, + newTreeEntry(VL, std::nullopt /*not vectorized*/, S, UserTreeIdx, ReuseShuffleIndicies); return; } @@ -5309,7 +5309,7 @@ void BoUpSLP::buildTree_rec(ArrayRef VL, unsigned Depth, return; } LLVM_DEBUG(dbgs() << "SLP: Gather extract sequence.\n"); - newTreeEntry(VL, None /*not vectorized*/, S, UserTreeIdx, + newTreeEntry(VL, std::nullopt /*not vectorized*/, S, UserTreeIdx, ReuseShuffleIndicies); BS.cancelScheduling(VL, VL0); return; @@ -5322,7 +5322,8 @@ void BoUpSLP::buildTree_rec(ArrayRef VL, unsigned Depth, ValueSet SourceVectors; for (Value *V : VL) { SourceVectors.insert(cast(V)->getOperand(0)); - assert(getInsertIndex(V) != None && "Non-constant or undef index?"); + assert(getInsertIndex(V) != std::nullopt && + "Non-constant or undef index?"); } if (count_if(VL, [&SourceVectors](Value *V) { @@ -5331,7 +5332,7 @@ void BoUpSLP::buildTree_rec(ArrayRef VL, unsigned Depth, // Found 2nd source vector - cancel. LLVM_DEBUG(dbgs() << "SLP: Gather of insertelement vectors with " "different source vectors.\n"); - newTreeEntry(VL, None /*not vectorized*/, S, UserTreeIdx); + newTreeEntry(VL, std::nullopt /*not vectorized*/, S, UserTreeIdx); BS.cancelScheduling(VL, VL0); return; } @@ -5357,7 +5358,7 @@ void BoUpSLP::buildTree_rec(ArrayRef VL, unsigned Depth, if (IsIdentity) CurrentOrder.clear(); TreeEntry *TE = newTreeEntry(VL, Bundle /*vectorized*/, S, UserTreeIdx, - None, CurrentOrder); + std::nullopt, CurrentOrder); LLVM_DEBUG(dbgs() << "SLP: added inserts bundle.\n"); constexpr int NumOps = 2; @@ -5408,7 +5409,7 @@ void BoUpSLP::buildTree_rec(ArrayRef VL, unsigned Depth, break; case LoadsState::Gather: BS.cancelScheduling(VL, VL0); - newTreeEntry(VL, None /*not vectorized*/, S, UserTreeIdx, + newTreeEntry(VL, std::nullopt /*not vectorized*/, S, UserTreeIdx, ReuseShuffleIndicies); #ifndef NDEBUG Type *ScalarTy = VL0->getType(); @@ -5443,7 +5444,7 @@ void BoUpSLP::buildTree_rec(ArrayRef VL, unsigned Depth, Type *Ty = cast(V)->getOperand(0)->getType(); if (Ty != SrcTy || !isValidElementType(Ty)) { BS.cancelScheduling(VL, VL0); - newTreeEntry(VL, None /*not vectorized*/, S, UserTreeIdx, + newTreeEntry(VL, std::nullopt /*not vectorized*/, S, UserTreeIdx, ReuseShuffleIndicies); LLVM_DEBUG(dbgs() << "SLP: Gathering casts with different src types.\n"); @@ -5476,7 +5477,7 @@ void BoUpSLP::buildTree_rec(ArrayRef VL, unsigned Depth, if ((Cmp->getPredicate() != P0 && Cmp->getPredicate() != SwapP0) || Cmp->getOperand(0)->getType() != ComparedTy) { BS.cancelScheduling(VL, VL0); - newTreeEntry(VL, None /*not vectorized*/, S, UserTreeIdx, + newTreeEntry(VL, std::nullopt /*not vectorized*/, S, UserTreeIdx, ReuseShuffleIndicies); LLVM_DEBUG(dbgs() << "SLP: Gathering cmp with different predicate.\n"); @@ -5568,7 +5569,7 @@ void BoUpSLP::buildTree_rec(ArrayRef VL, unsigned Depth, if (I->getNumOperands() != 2) { LLVM_DEBUG(dbgs() << "SLP: not-vectorizable GEP (nested indexes).\n"); BS.cancelScheduling(VL, VL0); - newTreeEntry(VL, None /*not vectorized*/, S, UserTreeIdx, + newTreeEntry(VL, std::nullopt /*not vectorized*/, S, UserTreeIdx, ReuseShuffleIndicies); return; } @@ -5586,7 +5587,7 @@ void BoUpSLP::buildTree_rec(ArrayRef VL, unsigned Depth, LLVM_DEBUG(dbgs() << "SLP: not-vectorizable GEP (different types).\n"); BS.cancelScheduling(VL, VL0); - newTreeEntry(VL, None /*not vectorized*/, S, UserTreeIdx, + newTreeEntry(VL, std::nullopt /*not vectorized*/, S, UserTreeIdx, ReuseShuffleIndicies); return; } @@ -5608,7 +5609,7 @@ void BoUpSLP::buildTree_rec(ArrayRef VL, unsigned Depth, LLVM_DEBUG(dbgs() << "SLP: not-vectorizable GEP (non-constant indexes).\n"); BS.cancelScheduling(VL, VL0); - newTreeEntry(VL, None /*not vectorized*/, S, UserTreeIdx, + newTreeEntry(VL, std::nullopt /*not vectorized*/, S, UserTreeIdx, ReuseShuffleIndicies); return; } @@ -5676,7 +5677,7 @@ void BoUpSLP::buildTree_rec(ArrayRef VL, unsigned Depth, if (DL->getTypeSizeInBits(ScalarTy) != DL->getTypeAllocSizeInBits(ScalarTy)) { BS.cancelScheduling(VL, VL0); - newTreeEntry(VL, None /*not vectorized*/, S, UserTreeIdx, + newTreeEntry(VL, std::nullopt /*not vectorized*/, S, UserTreeIdx, ReuseShuffleIndicies); LLVM_DEBUG(dbgs() << "SLP: Gathering stores of non-packed type.\n"); return; @@ -5691,7 +5692,7 @@ void BoUpSLP::buildTree_rec(ArrayRef VL, unsigned Depth, auto *SI = cast(V); if (!SI->isSimple()) { BS.cancelScheduling(VL, VL0); - newTreeEntry(VL, None /*not vectorized*/, S, UserTreeIdx, + newTreeEntry(VL, std::nullopt /*not vectorized*/, S, UserTreeIdx, ReuseShuffleIndicies); LLVM_DEBUG(dbgs() << "SLP: Gathering non-simple stores.\n"); return; @@ -5739,7 +5740,7 @@ void BoUpSLP::buildTree_rec(ArrayRef VL, unsigned Depth, } BS.cancelScheduling(VL, VL0); - newTreeEntry(VL, None /*not vectorized*/, S, UserTreeIdx, + newTreeEntry(VL, std::nullopt /*not vectorized*/, S, UserTreeIdx, ReuseShuffleIndicies); LLVM_DEBUG(dbgs() << "SLP: Non-consecutive store.\n"); return; @@ -5757,7 +5758,7 @@ void BoUpSLP::buildTree_rec(ArrayRef VL, unsigned Depth, if (!VecFunc && !isTriviallyVectorizable(ID)) { BS.cancelScheduling(VL, VL0); - newTreeEntry(VL, None /*not vectorized*/, S, UserTreeIdx, + newTreeEntry(VL, std::nullopt /*not vectorized*/, S, UserTreeIdx, ReuseShuffleIndicies); LLVM_DEBUG(dbgs() << "SLP: Non-vectorizable call.\n"); return; @@ -5776,7 +5777,7 @@ void BoUpSLP::buildTree_rec(ArrayRef VL, unsigned Depth, VecFunc != VFDatabase(*CI2).getVectorizedFunction(Shape)) || !CI->hasIdenticalOperandBundleSchema(*CI2)) { BS.cancelScheduling(VL, VL0); - newTreeEntry(VL, None /*not vectorized*/, S, UserTreeIdx, + newTreeEntry(VL, std::nullopt /*not vectorized*/, S, UserTreeIdx, ReuseShuffleIndicies); LLVM_DEBUG(dbgs() << "SLP: mismatched calls:" << *CI << "!=" << *V << "\n"); @@ -5789,7 +5790,7 @@ void BoUpSLP::buildTree_rec(ArrayRef VL, unsigned Depth, Value *A1J = CI2->getArgOperand(j); if (ScalarArgs[j] != A1J) { BS.cancelScheduling(VL, VL0); - newTreeEntry(VL, None /*not vectorized*/, S, UserTreeIdx, + newTreeEntry(VL, std::nullopt /*not vectorized*/, S, UserTreeIdx, ReuseShuffleIndicies); LLVM_DEBUG(dbgs() << "SLP: mismatched arguments in call:" << *CI << " argument " << ScalarArgs[j] << "!=" << A1J @@ -5804,7 +5805,7 @@ void BoUpSLP::buildTree_rec(ArrayRef VL, unsigned Depth, CI->op_begin() + CI->getBundleOperandsEndIndex(), CI2->op_begin() + CI2->getBundleOperandsStartIndex())) { BS.cancelScheduling(VL, VL0); - newTreeEntry(VL, None /*not vectorized*/, S, UserTreeIdx, + newTreeEntry(VL, std::nullopt /*not vectorized*/, S, UserTreeIdx, ReuseShuffleIndicies); LLVM_DEBUG(dbgs() << "SLP: mismatched bundle operands in calls:" << *CI << "!=" << *V << '\n'); @@ -5835,7 +5836,7 @@ void BoUpSLP::buildTree_rec(ArrayRef VL, unsigned Depth, // then do not vectorize this instruction. if (!S.isAltShuffle()) { BS.cancelScheduling(VL, VL0); - newTreeEntry(VL, None /*not vectorized*/, S, UserTreeIdx, + newTreeEntry(VL, std::nullopt /*not vectorized*/, S, UserTreeIdx, ReuseShuffleIndicies); LLVM_DEBUG(dbgs() << "SLP: ShuffleVector are not vectorized.\n"); return; @@ -5898,7 +5899,7 @@ void BoUpSLP::buildTree_rec(ArrayRef VL, unsigned Depth, } default: BS.cancelScheduling(VL, VL0); - newTreeEntry(VL, None /*not vectorized*/, S, UserTreeIdx, + newTreeEntry(VL, std::nullopt /*not vectorized*/, S, UserTreeIdx, ReuseShuffleIndicies); LLVM_DEBUG(dbgs() << "SLP: Gathering unknown instruction.\n"); return; @@ -6336,20 +6337,22 @@ InstructionCost BoUpSLP::getEntryCost(const TreeEntry *E, unsigned Idx = (Data.second / NumElts) * NumElts; unsigned EENumElts = EEVTy->getNumElements(); if (Idx + NumElts <= EENumElts) { - Cost += TTI->getShuffleCost(TargetTransformInfo::SK_ExtractSubvector, - EEVTy, None, CostKind, Idx, VecTy); + Cost += + TTI->getShuffleCost(TargetTransformInfo::SK_ExtractSubvector, + EEVTy, std::nullopt, CostKind, Idx, VecTy); } else { // Need to round up the subvector type vectorization factor to avoid a // crash in cost model functions. Make SubVT so that Idx + VF of SubVT // <= EENumElts. auto *SubVT = FixedVectorType::get(VecTy->getElementType(), EENumElts - Idx); - Cost += TTI->getShuffleCost(TargetTransformInfo::SK_ExtractSubvector, - EEVTy, None, CostKind, Idx, SubVT); + Cost += + TTI->getShuffleCost(TargetTransformInfo::SK_ExtractSubvector, + EEVTy, std::nullopt, CostKind, Idx, SubVT); } } else { Cost += TTI->getShuffleCost(TargetTransformInfo::SK_InsertSubvector, - VecTy, None, CostKind, 0, EEVTy); + VecTy, std::nullopt, CostKind, 0, EEVTy); } } }; @@ -6417,7 +6420,7 @@ InstructionCost BoUpSLP::getEntryCost(const TreeEntry *E, assert(VecTy == FinalVecTy && "No reused scalars expected for broadcast."); return TTI->getShuffleCost(TargetTransformInfo::SK_Broadcast, VecTy, - /*Mask=*/None, CostKind, /*Index=*/0, + /*Mask=*/std::nullopt, CostKind, /*Index=*/0, /*SubTp=*/nullptr, /*Args=*/VL[0]); } InstructionCost ReuseShuffleCost = 0; @@ -6507,8 +6510,9 @@ InstructionCost BoUpSLP::getEntryCost(const TreeEntry *E, if (NeedInsertSubvectorAnalysis) { // Add the cost for the subvectors insert. for (int I = VF, E = VL.size(); I < E; I += VF) - GatherCost += TTI->getShuffleCost(TTI::SK_InsertSubvector, VecTy, - None, CostKind, I, LoadTy); + GatherCost += + TTI->getShuffleCost(TTI::SK_InsertSubvector, VecTy, + std::nullopt, CostKind, I, LoadTy); } return ReuseShuffleCost + GatherCost - ScalarsCost; } @@ -6721,8 +6725,9 @@ InstructionCost BoUpSLP::getEntryCost(const TreeEntry *E, if (InsertVecSz != VecSz) { auto *ActualVecTy = FixedVectorType::get(SrcVecTy->getElementType(), VecSz); - Cost += TTI->getShuffleCost(TTI::SK_InsertSubvector, ActualVecTy, None, - CostKind, OffsetBeg - Offset, InsertVecTy); + Cost += TTI->getShuffleCost(TTI::SK_InsertSubvector, ActualVecTy, + std::nullopt, CostKind, OffsetBeg - Offset, + InsertVecTy); } else { for (unsigned I = 0, End = OffsetBeg - Offset; I < End; ++I) Mask[I] = InMask.test(I) ? UndefMaskElem : I; @@ -7693,7 +7698,7 @@ BoUpSLP::isGatherShuffledEntry(const TreeEntry *TE, SmallVectorImpl &Mask, if (const TreeEntry *VTE = getTreeEntry(V)) VToTEs.insert(VTE); if (VToTEs.empty()) - return None; + return std::nullopt; if (UsedTEs.empty()) { // The first iteration, just insert the list of nodes to vector. UsedTEs.push_back(VToTEs); @@ -7722,7 +7727,7 @@ BoUpSLP::isGatherShuffledEntry(const TreeEntry *TE, SmallVectorImpl &Mask, // If the number of input vectors is greater than 2 - not a permutation, // fallback to the regular gather. if (UsedTEs.size() == 2) - return None; + return std::nullopt; UsedTEs.push_back(SavedVToTEs); Idx = UsedTEs.size() - 1; } @@ -7733,7 +7738,7 @@ BoUpSLP::isGatherShuffledEntry(const TreeEntry *TE, SmallVectorImpl &Mask, if (UsedTEs.empty()) { assert(all_of(TE->Scalars, UndefValue::classof) && "Expected vector of undefs only."); - return None; + return std::nullopt; } unsigned VF = 0; @@ -7767,7 +7772,7 @@ BoUpSLP::isGatherShuffledEntry(const TreeEntry *TE, SmallVectorImpl &Mask, // No 2 source vectors with the same vector factor - give up and do regular // gather. if (Entries.empty()) - return None; + return std::nullopt; } // Build a shuffle mask for better cost estimation and vector emission. @@ -7782,7 +7787,7 @@ BoUpSLP::isGatherShuffledEntry(const TreeEntry *TE, SmallVectorImpl &Mask, // Extra check required by isSingleSourceMaskImpl function (called by // ShuffleVectorInst::isSingleSourceMask). if (Mask[I] >= 2 * E) - return None; + return std::nullopt; } switch (Entries.size()) { case 1: @@ -7792,7 +7797,7 @@ BoUpSLP::isGatherShuffledEntry(const TreeEntry *TE, SmallVectorImpl &Mask, default: break; } - return None; + return std::nullopt; } InstructionCost BoUpSLP::getGatherCost(FixedVectorType *Ty, @@ -9744,7 +9749,7 @@ BoUpSLP::BlockScheduling::tryScheduleBundle(ArrayRef VL, BoUpSLP *SLP, // dependencies and emit instruction in the wrong order at the actual // scheduling. TryScheduleBundleImpl(/*ReSchedule=*/false, nullptr); - return None; + return std::nullopt; } } @@ -9774,7 +9779,7 @@ BoUpSLP::BlockScheduling::tryScheduleBundle(ArrayRef VL, BoUpSLP *SLP, TryScheduleBundleImpl(ReSchedule, Bundle); if (!Bundle->isReady()) { cancelScheduling(VL, S.OpValue); - return None; + return std::nullopt; } return Bundle; } @@ -12259,7 +12264,7 @@ static Optional getAggregateSize(Instruction *InsertInst) { if (auto *ST = dyn_cast(CurrentType)) { for (auto *Elt : ST->elements()) if (Elt != ST->getElementType(0)) // check homogeneity - return None; + return std::nullopt; AggregateSize *= ST->getNumElements(); CurrentType = ST->getElementType(0); } else if (auto *AT = dyn_cast(CurrentType)) { @@ -12271,7 +12276,7 @@ static Optional getAggregateSize(Instruction *InsertInst) { } else if (CurrentType->isSingleValueType()) { return AggregateSize; } else { - return None; + return std::nullopt; } } while (true); } diff --git a/llvm/lib/Transforms/Vectorize/VPlanSLP.cpp b/llvm/lib/Transforms/Vectorize/VPlanSLP.cpp index 3ac45ea..fbcadba 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanSLP.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanSLP.cpp @@ -193,7 +193,7 @@ static std::optional getOpcode(ArrayRef Values) { if (any_of(Values, [Opcode](VPValue *V) { return cast(V)->getOpcode() != Opcode; })) - return None; + return std::nullopt; return {Opcode}; } -- 2.7.4