[clang] 89fae41 - [IR] llvm::Optional => std::optional
Fangrui Song via cfe-commits
cfe-commits at lists.llvm.org
Sun Dec 4 20:13:19 PST 2022
Author: Fangrui Song
Date: 2022-12-05T04:13:11Z
New Revision: 89fae41ef142892d8d6c20ead28465a34e12172b
URL: https://github.com/llvm/llvm-project/commit/89fae41ef142892d8d6c20ead28465a34e12172b
DIFF: https://github.com/llvm/llvm-project/commit/89fae41ef142892d8d6c20ead28465a34e12172b.diff
LOG: [IR] llvm::Optional => std::optional
Many llvm/IR/* files have been migrated by other contributors.
This migrates most remaining files.
Added:
Modified:
clang/include/clang/Basic/CodeGenOptions.h
clang/lib/Frontend/CompilerInvocation.cpp
llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h
llvm/include/llvm/AsmParser/LLParser.h
llvm/include/llvm/CodeGen/MachineBasicBlock.h
llvm/include/llvm/IR/BasicBlock.h
llvm/include/llvm/IR/ConstantFold.h
llvm/include/llvm/IR/ConstantRange.h
llvm/include/llvm/IR/Constants.h
llvm/include/llvm/IR/DataLayout.h
llvm/include/llvm/IR/DiagnosticInfo.h
llvm/include/llvm/IR/Function.h
llvm/include/llvm/IR/GCStrategy.h
llvm/include/llvm/IR/GlobalValue.h
llvm/include/llvm/IR/GlobalVariable.h
llvm/include/llvm/IR/Intrinsics.h
llvm/include/llvm/IR/LLVMContext.h
llvm/include/llvm/IR/Module.h
llvm/include/llvm/IR/Operator.h
llvm/include/llvm/IR/PseudoProbe.h
llvm/include/llvm/IR/Statepoint.h
llvm/include/llvm/IR/ValueMap.h
llvm/lib/Analysis/ConstantFolding.cpp
llvm/lib/AsmParser/LLParser.cpp
llvm/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
llvm/lib/CodeGen/MachineFunctionSplitter.cpp
llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
llvm/lib/IR/AsmWriter.cpp
llvm/lib/IR/BasicBlock.cpp
llvm/lib/IR/BuiltinGCs.cpp
llvm/lib/IR/ConstantFold.cpp
llvm/lib/IR/ConstantRange.cpp
llvm/lib/IR/Constants.cpp
llvm/lib/IR/DataLayout.cpp
llvm/lib/IR/Function.cpp
llvm/lib/IR/Globals.cpp
llvm/lib/IR/LLVMContext.cpp
llvm/lib/IR/LLVMContextImpl.h
llvm/lib/IR/Module.cpp
llvm/lib/IR/PassManager.cpp
llvm/lib/IR/PseudoProbe.cpp
llvm/lib/IR/Verifier.cpp
llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
llvm/lib/Target/X86/X86Subtarget.cpp
llvm/lib/Transforms/IPO/SampleProfile.cpp
llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
llvm/lib/Transforms/Scalar/GuardWidening.cpp
llvm/lib/Transforms/Utils/Evaluator.cpp
llvm/lib/Transforms/Utils/ValueMapper.cpp
llvm/tools/llvm-reduce/ReducerWorkItem.cpp
llvm/unittests/IR/ConstantRangeTest.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/CodeGenOptions.h b/clang/include/clang/Basic/CodeGenOptions.h
index 101e4761992f2..24cc56c8e05df 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -430,7 +430,7 @@ class CodeGenOptions : public CodeGenOptionsBase {
/// The maximum percentage profiling weights can deviate from the expected
/// values in order to be included in misexpect diagnostics.
- Optional<uint32_t> DiagnosticsMisExpectTolerance = 0;
+ std::optional<uint32_t> DiagnosticsMisExpectTolerance = 0;
/// The name of a file to use with \c .secure_log_unique directives.
std::string AsSecureLogFile;
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index e9ad41262c3f8..5a8e92139854d 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -115,7 +115,7 @@ using namespace llvm::opt;
// Parse misexpect tolerance argument value.
// Valid option values are integers in the range [0, 100)
-inline Expected<Optional<uint32_t>> parseToleranceOption(StringRef Arg) {
+static Expected<std::optional<uint32_t>> parseToleranceOption(StringRef Arg) {
uint32_t Val;
if (Arg.getAsInteger(10, Val))
return llvm::createStringError(llvm::inconvertibleErrorCode(),
diff --git a/llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h b/llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h
index 9138248d08aa2..0e9cac076902c 100644
--- a/llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h
+++ b/llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h
@@ -1270,7 +1270,7 @@ bool BlockFrequencyInfoImpl<BT>::computeMassInLoop(LoopData &Loop) {
auto &HeaderNode = Loop.Nodes[H];
const BlockT *Block = getBlock(HeaderNode);
IsIrrLoopHeader.set(Loop.Nodes[H].Index);
- Optional<uint64_t> HeaderWeight = Block->getIrrLoopHeaderWeight();
+ std::optional<uint64_t> HeaderWeight = Block->getIrrLoopHeaderWeight();
if (!HeaderWeight) {
LLVM_DEBUG(dbgs() << "Missing irr loop header metadata on "
<< getBlockName(HeaderNode) << "\n");
@@ -1734,8 +1734,8 @@ raw_ostream &BlockFrequencyInfoImpl<BT>::print(raw_ostream &OS) const {
BlockFrequencyInfoImplBase::getBlockProfileCount(
F->getFunction(), getNode(&BB)))
OS << ", count = " << ProfileCount.value();
- if (Optional<uint64_t> IrrLoopHeaderWeight =
- BB.getIrrLoopHeaderWeight())
+ if (std::optional<uint64_t> IrrLoopHeaderWeight =
+ BB.getIrrLoopHeaderWeight())
OS << ", irr_loop_header_weight = " << IrrLoopHeaderWeight.value();
OS << "\n";
}
diff --git a/llvm/include/llvm/AsmParser/LLParser.h b/llvm/include/llvm/AsmParser/LLParser.h
index f2fba49ab7054..862b9ed29394c 100644
--- a/llvm/include/llvm/AsmParser/LLParser.h
+++ b/llvm/include/llvm/AsmParser/LLParser.h
@@ -539,7 +539,7 @@ namespace llvm {
bool parseGlobalValue(Type *Ty, Constant *&C);
bool parseGlobalTypeAndValue(Constant *&V);
bool parseGlobalValueVector(SmallVectorImpl<Constant *> &Elts,
- Optional<unsigned> *InRangeOp = nullptr);
+ std::optional<unsigned> *InRangeOp = nullptr);
bool parseOptionalComdat(StringRef GlobalName, Comdat *&C);
bool parseSanitizer(GlobalVariable *GV);
bool parseMetadataAsValue(Value *&V, PerFunctionState &PFS);
diff --git a/llvm/include/llvm/CodeGen/MachineBasicBlock.h b/llvm/include/llvm/CodeGen/MachineBasicBlock.h
index fe4ad270f2a3b..a1c1d0395da4d 100644
--- a/llvm/include/llvm/CodeGen/MachineBasicBlock.h
+++ b/llvm/include/llvm/CodeGen/MachineBasicBlock.h
@@ -126,7 +126,7 @@ class MachineBasicBlock
using const_probability_iterator =
std::vector<BranchProbability>::const_iterator;
- Optional<uint64_t> IrrLoopHeaderWeight;
+ std::optional<uint64_t> IrrLoopHeaderWeight;
/// Keep track of the physical registers that are livein of the basicblock.
using LiveInVector = std::vector<RegisterMaskPair>;
@@ -1121,7 +1121,7 @@ class MachineBasicBlock
/// Return the EHCatchret Symbol for this basic block.
MCSymbol *getEHCatchretSymbol() const;
- Optional<uint64_t> getIrrLoopHeaderWeight() const {
+ std::optional<uint64_t> getIrrLoopHeaderWeight() const {
return IrrLoopHeaderWeight;
}
diff --git a/llvm/include/llvm/IR/BasicBlock.h b/llvm/include/llvm/IR/BasicBlock.h
index 57a2ace099ad2..9a6def27bc7f0 100644
--- a/llvm/include/llvm/IR/BasicBlock.h
+++ b/llvm/include/llvm/IR/BasicBlock.h
@@ -520,7 +520,7 @@ class BasicBlock final : public Value, // Basic blocks are data objects also
/// This method can only be used on blocks that have a parent function.
bool isEntryBlock() const;
- Optional<uint64_t> getIrrLoopHeaderWeight() const;
+ std::optional<uint64_t> getIrrLoopHeaderWeight() const;
/// Returns true if the Order field of child Instructions is valid.
bool isInstrOrderValid() const {
diff --git a/llvm/include/llvm/IR/ConstantFold.h b/llvm/include/llvm/IR/ConstantFold.h
index d637a180b0ba6..77f5f0eb174a2 100644
--- a/llvm/include/llvm/IR/ConstantFold.h
+++ b/llvm/include/llvm/IR/ConstantFold.h
@@ -21,8 +21,8 @@
#ifndef LLVM_IR_CONSTANTFOLD_H
#define LLVM_IR_CONSTANTFOLD_H
-#include "llvm/ADT/Optional.h"
#include "llvm/IR/InstrTypes.h"
+#include <optional>
namespace llvm {
template <typename T> class ArrayRef;
@@ -53,7 +53,7 @@ namespace llvm {
Constant *ConstantFoldCompareInstruction(CmpInst::Predicate Predicate,
Constant *C1, Constant *C2);
Constant *ConstantFoldGetElementPtr(Type *Ty, Constant *C, bool InBounds,
- Optional<unsigned> InRangeIndex,
+ std::optional<unsigned> InRangeIndex,
ArrayRef<Value *> Idxs);
} // End llvm namespace
diff --git a/llvm/include/llvm/IR/ConstantRange.h b/llvm/include/llvm/IR/ConstantRange.h
index 4bbc8407b5241..0b9ac18d0a928 100644
--- a/llvm/include/llvm/IR/ConstantRange.h
+++ b/llvm/include/llvm/IR/ConstantRange.h
@@ -334,11 +334,12 @@ class [[nodiscard]] ConstantRange {
/// Intersect the two ranges and return the result if it can be represented
/// exactly, otherwise return std::nullopt.
- Optional<ConstantRange> exactIntersectWith(const ConstantRange &CR) const;
+ std::optional<ConstantRange>
+ exactIntersectWith(const ConstantRange &CR) const;
/// Union the two ranges and return the result if it can be represented
/// exactly, otherwise return std::nullopt.
- Optional<ConstantRange> exactUnionWith(const ConstantRange &CR) const;
+ std::optional<ConstantRange> exactUnionWith(const ConstantRange &CR) const;
/// Return a new range representing the possible values resulting
/// from an application of the specified cast operator to this range. \p
diff --git a/llvm/include/llvm/IR/Constants.h b/llvm/include/llvm/IR/Constants.h
index d39445832f790..f6c1986f38238 100644
--- a/llvm/include/llvm/IR/Constants.h
+++ b/llvm/include/llvm/IR/Constants.h
@@ -24,7 +24,6 @@
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/None.h"
-#include "llvm/ADT/Optional.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/IR/Constant.h"
@@ -38,6 +37,7 @@
#include <cassert>
#include <cstddef>
#include <cstdint>
+#include <optional>
namespace llvm {
@@ -1218,7 +1218,7 @@ class ConstantExpr : public Constant {
static Constant *
getGetElementPtr(Type *Ty, Constant *C, ArrayRef<Constant *> IdxList,
bool InBounds = false,
- Optional<unsigned> InRangeIndex = std::nullopt,
+ std::optional<unsigned> InRangeIndex = std::nullopt,
Type *OnlyIfReducedTy = nullptr) {
return getGetElementPtr(
Ty, C, makeArrayRef((Value *const *)IdxList.data(), IdxList.size()),
@@ -1226,7 +1226,7 @@ class ConstantExpr : public Constant {
}
static Constant *
getGetElementPtr(Type *Ty, Constant *C, Constant *Idx, bool InBounds = false,
- Optional<unsigned> InRangeIndex = std::nullopt,
+ std::optional<unsigned> InRangeIndex = std::nullopt,
Type *OnlyIfReducedTy = nullptr) {
// This form of the function only exists to avoid ambiguous overload
// warnings about whether to convert Idx to ArrayRef<Constant *> or
@@ -1237,7 +1237,7 @@ class ConstantExpr : public Constant {
static Constant *
getGetElementPtr(Type *Ty, Constant *C, ArrayRef<Value *> IdxList,
bool InBounds = false,
- Optional<unsigned> InRangeIndex = std::nullopt,
+ std::optional<unsigned> InRangeIndex = std::nullopt,
Type *OnlyIfReducedTy = nullptr);
/// Create an "inbounds" getelementptr. See the documentation for the
diff --git a/llvm/include/llvm/IR/DataLayout.h b/llvm/include/llvm/IR/DataLayout.h
index d607c2a766793..f4174ede22fbd 100644
--- a/llvm/include/llvm/IR/DataLayout.h
+++ b/llvm/include/llvm/IR/DataLayout.h
@@ -595,7 +595,7 @@ class DataLayout {
/// if index cannot be computed, e.g. because the type is not an aggregate.
/// ElemTy is updated to be the result element type and Offset to be the
/// residual offset.
- Optional<APInt> getGEPIndexForOffset(Type *&ElemTy, APInt &Offset) const;
+ std::optional<APInt> getGEPIndexForOffset(Type *&ElemTy, APInt &Offset) const;
/// Returns a StructLayout object, indicating the alignment of the
/// struct, its size, and the offsets of its fields.
diff --git a/llvm/include/llvm/IR/DiagnosticInfo.h b/llvm/include/llvm/IR/DiagnosticInfo.h
index 0a1c4abdd56af..f3abce37b1678 100644
--- a/llvm/include/llvm/IR/DiagnosticInfo.h
+++ b/llvm/include/llvm/IR/DiagnosticInfo.h
@@ -16,7 +16,6 @@
#include "llvm-c/Types.h"
#include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/Optional.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
@@ -29,6 +28,7 @@
#include <cstdint>
#include <functional>
#include <iterator>
+#include <optional>
#include <string>
namespace llvm {
diff --git a/llvm/include/llvm/IR/Function.h b/llvm/include/llvm/IR/Function.h
index 22e98e91d4580..2ad19e6eafc06 100644
--- a/llvm/include/llvm/IR/Function.h
+++ b/llvm/include/llvm/IR/Function.h
@@ -280,7 +280,7 @@ class LLVM_EXTERNAL_VISIBILITY Function : public GlobalObject,
///
/// Entry count is the number of times the function was executed.
/// When AllowSynthetic is false, only pgo_data will be returned.
- Optional<ProfileCount> getEntryCount(bool AllowSynthetic = false) const;
+ std::optional<ProfileCount> getEntryCount(bool AllowSynthetic = false) const;
/// Return true if the function is annotated with profile data.
///
@@ -299,7 +299,7 @@ class LLVM_EXTERNAL_VISIBILITY Function : public GlobalObject,
void setSectionPrefix(StringRef Prefix);
/// Get the section prefix for this function.
- Optional<StringRef> getSectionPrefix() const;
+ std::optional<StringRef> getSectionPrefix() const;
/// hasGC/getGC/setGC/clearGC - The name of the garbage collection algorithm
/// to use during code generation.
diff --git a/llvm/include/llvm/IR/GCStrategy.h b/llvm/include/llvm/IR/GCStrategy.h
index b83a4bf72608b..660ac3d479938 100644
--- a/llvm/include/llvm/IR/GCStrategy.h
+++ b/llvm/include/llvm/IR/GCStrategy.h
@@ -48,8 +48,8 @@
#define LLVM_IR_GCSTRATEGY_H
#include "llvm/ADT/None.h"
-#include "llvm/ADT/Optional.h"
#include "llvm/Support/Registry.h"
+#include <optional>
#include <string>
namespace llvm {
@@ -94,7 +94,7 @@ class GCStrategy {
/// pointers to GC managed locations and false for pointers to non-GC
/// managed locations. Note a GCStrategy can always return 'None' (i.e. an
/// empty optional indicating it can't reliably distinguish.
- virtual Optional<bool> isGCManagedPointer(const Type *Ty) const {
+ virtual std::optional<bool> isGCManagedPointer(const Type *Ty) const {
return std::nullopt;
}
///@}
diff --git a/llvm/include/llvm/IR/GlobalValue.h b/llvm/include/llvm/IR/GlobalValue.h
index f92e1a324dad4..b0e17d9553f79 100644
--- a/llvm/include/llvm/IR/GlobalValue.h
+++ b/llvm/include/llvm/IR/GlobalValue.h
@@ -638,8 +638,8 @@ class GlobalValue : public Constant {
bool isAbsoluteSymbolRef() const;
/// If this is an absolute symbol reference, returns the range of the symbol,
- /// otherwise returns std::nullopt.
- Optional<ConstantRange> getAbsoluteSymbolRange() const;
+ /// otherwise returns None.
+ std::optional<ConstantRange> getAbsoluteSymbolRange() const;
/// This method unlinks 'this' from the containing module, but does not delete
/// it.
diff --git a/llvm/include/llvm/IR/GlobalVariable.h b/llvm/include/llvm/IR/GlobalVariable.h
index 9db5b04c14922..03c680e4f9558 100644
--- a/llvm/include/llvm/IR/GlobalVariable.h
+++ b/llvm/include/llvm/IR/GlobalVariable.h
@@ -59,7 +59,7 @@ class GlobalVariable : public GlobalObject, public ilist_node<GlobalVariable> {
Constant *Initializer, const Twine &Name = "",
GlobalVariable *InsertBefore = nullptr,
ThreadLocalMode = NotThreadLocal,
- Optional<unsigned> AddressSpace = std::nullopt,
+ std::optional<unsigned> AddressSpace = std::nullopt,
bool isExternallyInitialized = false);
GlobalVariable(const GlobalVariable &) = delete;
GlobalVariable &operator=(const GlobalVariable &) = delete;
diff --git a/llvm/include/llvm/IR/Intrinsics.h b/llvm/include/llvm/IR/Intrinsics.h
index 559e5eef5259e..7459ea9e689d0 100644
--- a/llvm/include/llvm/IR/Intrinsics.h
+++ b/llvm/include/llvm/IR/Intrinsics.h
@@ -17,8 +17,8 @@
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/None.h"
-#include "llvm/ADT/Optional.h"
#include "llvm/Support/TypeSize.h"
+#include <optional>
#include <string>
namespace llvm {
@@ -250,7 +250,7 @@ namespace Intrinsic {
// returns the declaration with the same signature and remangled name.
// An existing GlobalValue with the wanted name but with a wrong prototype
// or of the wrong kind will be renamed by adding ".renamed" to the name.
- llvm::Optional<Function*> remangleIntrinsicFunction(Function *F);
+ std::optional<Function *> remangleIntrinsicFunction(Function *F);
} // End Intrinsic namespace
diff --git a/llvm/include/llvm/IR/LLVMContext.h b/llvm/include/llvm/IR/LLVMContext.h
index 55c68691730fb..c380ed215b6cc 100644
--- a/llvm/include/llvm/IR/LLVMContext.h
+++ b/llvm/include/llvm/IR/LLVMContext.h
@@ -15,11 +15,11 @@
#define LLVM_IR_LLVMCONTEXT_H
#include "llvm-c/Types.h"
-#include "llvm/ADT/Optional.h"
#include "llvm/IR/DiagnosticHandler.h"
#include "llvm/Support/CBindingWrapping.h"
#include <cstdint>
#include <memory>
+#include <optional>
#include <string>
namespace llvm {
@@ -205,7 +205,7 @@ class LLVMContext {
bool getMisExpectWarningRequested() const;
void setMisExpectWarningRequested(bool Requested);
- void setDiagnosticsMisExpectTolerance(Optional<uint32_t> Tolerance);
+ void setDiagnosticsMisExpectTolerance(std::optional<uint32_t> Tolerance);
uint32_t getDiagnosticsMisExpectTolerance() const;
/// Return the minimum hotness value a diagnostic would need in order
diff --git a/llvm/include/llvm/IR/Module.h b/llvm/include/llvm/IR/Module.h
index 0dd1b81326a30..cd71a848addbb 100644
--- a/llvm/include/llvm/IR/Module.h
+++ b/llvm/include/llvm/IR/Module.h
@@ -15,7 +15,6 @@
#define LLVM_IR_MODULE_H
#include "llvm-c/Types.h"
-#include "llvm/ADT/Optional.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
diff --git a/llvm/include/llvm/IR/Operator.h b/llvm/include/llvm/IR/Operator.h
index ed52535c0b6e9..215b1d36837e5 100644
--- a/llvm/include/llvm/IR/Operator.h
+++ b/llvm/include/llvm/IR/Operator.h
@@ -16,7 +16,6 @@
#include "llvm/ADT/MapVector.h"
#include "llvm/ADT/None.h"
-#include "llvm/ADT/Optional.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/FMF.h"
#include "llvm/IR/Instruction.h"
@@ -24,6 +23,7 @@
#include "llvm/IR/Value.h"
#include "llvm/Support/Casting.h"
#include <cstddef>
+#include <optional>
namespace llvm {
@@ -395,7 +395,7 @@ class GEPOperator
/// Returns the offset of the index with an inrange attachment, or
/// std::nullopt if none.
- Optional<unsigned> getInRangeIndex() const {
+ std::optional<unsigned> getInRangeIndex() const {
if (SubclassOptionalData >> 1 == 0)
return std::nullopt;
return (SubclassOptionalData >> 1) - 1;
diff --git a/llvm/include/llvm/IR/PseudoProbe.h b/llvm/include/llvm/IR/PseudoProbe.h
index 1c109eafde573..79726c0eee8be 100644
--- a/llvm/include/llvm/IR/PseudoProbe.h
+++ b/llvm/include/llvm/IR/PseudoProbe.h
@@ -13,10 +13,10 @@
#ifndef LLVM_IR_PSEUDOPROBE_H
#define LLVM_IR_PSEUDOPROBE_H
-#include "llvm/ADT/Optional.h"
#include <cassert>
#include <cstdint>
#include <limits>
+#include <optional>
namespace llvm {
@@ -91,7 +91,7 @@ static inline bool isSentinelProbe(uint32_t Flags) {
return Flags & (uint32_t)PseudoProbeAttributes::Sentinel;
}
-Optional<PseudoProbe> extractProbe(const Instruction &Inst);
+std::optional<PseudoProbe> extractProbe(const Instruction &Inst);
void setProbeDistributionFactor(Instruction &Inst, float Factor);
} // end namespace llvm
diff --git a/llvm/include/llvm/IR/Statepoint.h b/llvm/include/llvm/IR/Statepoint.h
index 8b6ffd2e0897b..21c4a3eaa5ac2 100644
--- a/llvm/include/llvm/IR/Statepoint.h
+++ b/llvm/include/llvm/IR/Statepoint.h
@@ -16,7 +16,6 @@
#ifndef LLVM_IR_STATEPOINT_H
#define LLVM_IR_STATEPOINT_H
-#include "llvm/ADT/Optional.h"
#include "llvm/ADT/iterator_range.h"
#include "llvm/IR/Attributes.h"
#include "llvm/IR/Constants.h"
diff --git a/llvm/include/llvm/IR/ValueMap.h b/llvm/include/llvm/IR/ValueMap.h
index a8c9056310552..5e26f68efdc85 100644
--- a/llvm/include/llvm/IR/ValueMap.h
+++ b/llvm/include/llvm/IR/ValueMap.h
@@ -28,7 +28,6 @@
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseMapInfo.h"
#include "llvm/ADT/None.h"
-#include "llvm/ADT/Optional.h"
#include "llvm/IR/TrackingMDRef.h"
#include "llvm/IR/ValueHandle.h"
#include "llvm/Support/Casting.h"
@@ -38,6 +37,7 @@
#include <cstddef>
#include <iterator>
#include <mutex>
+#include <optional>
#include <type_traits>
#include <utility>
@@ -91,7 +91,7 @@ class ValueMap {
using ExtraData = typename Config::ExtraData;
MapT Map;
- Optional<MDMapT> MDMap;
+ std::optional<MDMapT> MDMap;
ExtraData Data;
public:
@@ -117,10 +117,10 @@ class ValueMap {
MDMap.emplace();
return *MDMap;
}
- Optional<MDMapT> &getMDMap() { return MDMap; }
+ std::optional<MDMapT> &getMDMap() { return MDMap; }
/// Get the mapped metadata, if it's in the map.
- Optional<Metadata *> getMappedMD(const Metadata *MD) const {
+ std::optional<Metadata *> getMappedMD(const Metadata *MD) const {
if (!MDMap)
return std::nullopt;
auto Where = MDMap->find(MD);
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index f2a56d6249a54..f07113af84046 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -825,7 +825,7 @@ Constant *SymbolicallyEvaluateBinop(unsigned Opc, Constant *Op0, Constant *Op1,
/// If array indices are not pointer-sized integers, explicitly cast them so
/// that they aren't implicitly casted by the getelementptr.
Constant *CastGEPIndices(Type *SrcElemTy, ArrayRef<Constant *> Ops,
- Type *ResultTy, Optional<unsigned> InRangeIndex,
+ Type *ResultTy, std::optional<unsigned> InRangeIndex,
const DataLayout &DL, const TargetLibraryInfo *TLI) {
Type *IntIdxTy = DL.getIndexType(ResultTy);
Type *IntIdxScalarTy = IntIdxTy->getScalarType();
@@ -992,8 +992,8 @@ Constant *SymbolicallyEvaluateGEP(const GEPOperator *GEP,
// Preserve the inrange index from the innermost GEP if possible. We must
// have calculated the same indices up to and including the inrange index.
- Optional<unsigned> InRangeIndex;
- if (Optional<unsigned> LastIRIndex = InnermostGEP->getInRangeIndex())
+ std::optional<unsigned> InRangeIndex;
+ if (std::optional<unsigned> LastIRIndex = InnermostGEP->getInRangeIndex())
if (SrcElemTy == InnermostGEP->getSourceElementType() &&
NewIdxs.size() > *LastIRIndex) {
InRangeIndex = LastIRIndex;
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index 2c1a94b12b31b..76cb5ee6944f8 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -3855,7 +3855,7 @@ bool LLParser::parseValID(ValID &ID, PerFunctionState *PFS, Type *ExpectedTy) {
return true;
}
- Optional<unsigned> InRangeOp;
+ std::optional<unsigned> InRangeOp;
if (parseGlobalValueVector(
Elts, Opc == Instruction::GetElementPtr ? &InRangeOp : nullptr) ||
parseToken(lltok::rparen, "expected ')' in constantexpr"))
@@ -3998,7 +3998,7 @@ bool LLParser::parseOptionalComdat(StringRef GlobalName, Comdat *&C) {
/// ::= /*empty*/
/// ::= [inrange] TypeAndValue (',' [inrange] TypeAndValue)*
bool LLParser::parseGlobalValueVector(SmallVectorImpl<Constant *> &Elts,
- Optional<unsigned> *InRangeOp) {
+ std::optional<unsigned> *InRangeOp) {
// Empty list.
if (Lex.getKind() == lltok::rbrace ||
Lex.getKind() == lltok::rsquare ||
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 1d5d10a22728b..b5f185171ba1c 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -551,7 +551,7 @@ class BitcodeConstant final : public Value,
return makeArrayRef(getTrailingObjects<unsigned>(), NumOperands);
}
- Optional<unsigned> getInRangeIndex() const {
+ std::optional<unsigned> getInRangeIndex() const {
assert(Opcode == Instruction::GetElementPtr);
if (Extra == (unsigned)-1)
return std::nullopt;
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index ff64435e75881..12358bbf8d0de 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -2657,7 +2657,7 @@ void ModuleBitcodeWriter::writeConstants(unsigned FirstVal, unsigned LastVal,
Code = bitc::CST_CODE_CE_GEP;
const auto *GO = cast<GEPOperator>(C);
Record.push_back(VE.getTypeID(GO->getSourceElementType()));
- if (Optional<unsigned> Idx = GO->getInRangeIndex()) {
+ if (std::optional<unsigned> Idx = GO->getInRangeIndex()) {
Code = bitc::CST_CODE_CE_GEP_WITH_INRANGE_INDEX;
Record.push_back((*Idx << 1) | GO->isInBounds());
} else if (GO->isInBounds())
diff --git a/llvm/lib/CodeGen/MachineFunctionSplitter.cpp b/llvm/lib/CodeGen/MachineFunctionSplitter.cpp
index e8d233385161c..29caf7204c426 100644
--- a/llvm/lib/CodeGen/MachineFunctionSplitter.cpp
+++ b/llvm/lib/CodeGen/MachineFunctionSplitter.cpp
@@ -185,7 +185,7 @@ bool MachineFunctionSplitter::runOnMachineFunction(MachineFunction &MF) {
// We don't want to proceed further for cold functions
// or functions of unknown hotness. Lukewarm functions have no prefix.
- Optional<StringRef> SectionPrefix = MF.getFunction().getSectionPrefix();
+ std::optional<StringRef> SectionPrefix = MF.getFunction().getSectionPrefix();
if (SectionPrefix && (SectionPrefix.value().equals("unlikely") ||
SectionPrefix.value().equals("unknown"))) {
return false;
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index b9ee79031425c..b2d56adfbeab3 100644
--- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -670,7 +670,7 @@ getELFSectionNameForGlobal(const GlobalObject *GO, SectionKind Kind,
bool HasPrefix = false;
if (const auto *F = dyn_cast<Function>(GO)) {
- if (Optional<StringRef> Prefix = F->getSectionPrefix()) {
+ if (std::optional<StringRef> Prefix = F->getSectionPrefix()) {
raw_svector_ostream(Name) << '.' << *Prefix;
HasPrefix = true;
}
@@ -1720,7 +1720,7 @@ MCSection *TargetLoweringObjectFileCOFF::SelectSectionForGlobal(
StringRef COMDATSymName = Sym->getName();
if (const auto *F = dyn_cast<Function>(GO))
- if (Optional<StringRef> Prefix = F->getSectionPrefix())
+ if (std::optional<StringRef> Prefix = F->getSectionPrefix())
raw_svector_ostream(Name) << '$' << *Prefix;
// Append "$symbol" to the section name *before* IR-level mangling is
diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp
index af80b47449e42..3ca17648a7032 100644
--- a/llvm/lib/IR/AsmWriter.cpp
+++ b/llvm/lib/IR/AsmWriter.cpp
@@ -20,7 +20,6 @@
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/None.h"
-#include "llvm/ADT/Optional.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/SmallPtrSet.h"
@@ -1580,7 +1579,7 @@ static void WriteConstantInternal(raw_ostream &Out, const Constant *CV,
static_cast<CmpInst::Predicate>(CE->getPredicate()));
Out << " (";
- Optional<unsigned> InRangeOp;
+ std::optional<unsigned> InRangeOp;
if (const GEPOperator *GEP = dyn_cast<GEPOperator>(CE)) {
WriterCtx.TypePrinter->print(GEP->getSourceElementType(), Out);
Out << ", ";
@@ -1676,7 +1675,7 @@ struct MDFieldPrinter {
void printAPInt(StringRef Name, const APInt &Int, bool IsUnsigned,
bool ShouldSkipZero);
void printBool(StringRef Name, bool Value,
- Optional<bool> Default = std::nullopt);
+ std::optional<bool> Default = std::nullopt);
void printDIFlags(StringRef Name, DINode::DIFlags Flags);
void printDISPFlags(StringRef Name, DISubprogram::DISPFlags Flags);
template <class IntTy, class Stringifier>
@@ -1760,7 +1759,7 @@ void MDFieldPrinter::printAPInt(StringRef Name, const APInt &Int,
}
void MDFieldPrinter::printBool(StringRef Name, bool Value,
- Optional<bool> Default) {
+ std::optional<bool> Default) {
if (Default && Value == *Default)
return;
Out << FS << Name << ": " << (Value ? "true" : "false");
diff --git a/llvm/lib/IR/BasicBlock.cpp b/llvm/lib/IR/BasicBlock.cpp
index 7a30005eb981f..f2ecd6ea3c852 100644
--- a/llvm/lib/IR/BasicBlock.cpp
+++ b/llvm/lib/IR/BasicBlock.cpp
@@ -519,14 +519,14 @@ const LandingPadInst *BasicBlock::getLandingPadInst() const {
return dyn_cast<LandingPadInst>(getFirstNonPHI());
}
-Optional<uint64_t> BasicBlock::getIrrLoopHeaderWeight() const {
+std::optional<uint64_t> BasicBlock::getIrrLoopHeaderWeight() const {
const Instruction *TI = getTerminator();
if (MDNode *MDIrrLoopHeader =
TI->getMetadata(LLVMContext::MD_irr_loop)) {
MDString *MDName = cast<MDString>(MDIrrLoopHeader->getOperand(0));
if (MDName->getString().equals("loop_header_weight")) {
auto *CI = mdconst::extract<ConstantInt>(MDIrrLoopHeader->getOperand(1));
- return Optional<uint64_t>(CI->getValue().getZExtValue());
+ return std::optional<uint64_t>(CI->getValue().getZExtValue());
}
}
return std::nullopt;
diff --git a/llvm/lib/IR/BuiltinGCs.cpp b/llvm/lib/IR/BuiltinGCs.cpp
index dc7cb815f7d42..1a7100a0d7a9d 100644
--- a/llvm/lib/IR/BuiltinGCs.cpp
+++ b/llvm/lib/IR/BuiltinGCs.cpp
@@ -72,7 +72,7 @@ class StatepointGC : public GCStrategy {
UsesMetadata = false;
}
- Optional<bool> isGCManagedPointer(const Type *Ty) const override {
+ std::optional<bool> isGCManagedPointer(const Type *Ty) const override {
// Method is only valid on pointer typed values.
const PointerType *PT = cast<PointerType>(Ty);
// For the sake of this example GC, we arbitrarily pick addrspace(1) as our
@@ -104,7 +104,7 @@ class CoreCLRGC : public GCStrategy {
UsesMetadata = false;
}
- Optional<bool> isGCManagedPointer(const Type *Ty) const override {
+ std::optional<bool> isGCManagedPointer(const Type *Ty) const override {
// Method is only valid on pointer typed values.
const PointerType *PT = cast<PointerType>(Ty);
// We pick addrspace(1) as our GC managed heap.
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp
index 1815bba021385..a487aa4145a1d 100644
--- a/llvm/lib/IR/ConstantFold.cpp
+++ b/llvm/lib/IR/ConstantFold.cpp
@@ -2022,7 +2022,7 @@ static Constant *foldGEPOfGEP(GEPOperator *GEP, Type *PointeeTy, bool InBounds,
// The combined GEP normally inherits its index inrange attribute from
// the inner GEP, but if the inner GEP's last index was adjusted by the
// outer GEP, any inbounds attribute on that index is invalidated.
- Optional<unsigned> IRIndex = GEP->getInRangeIndex();
+ std::optional<unsigned> IRIndex = GEP->getInRangeIndex();
if (IRIndex && *IRIndex == GEP->getNumIndices() - 1)
IRIndex = std::nullopt;
@@ -2033,7 +2033,7 @@ static Constant *foldGEPOfGEP(GEPOperator *GEP, Type *PointeeTy, bool InBounds,
Constant *llvm::ConstantFoldGetElementPtr(Type *PointeeTy, Constant *C,
bool InBounds,
- Optional<unsigned> InRangeIndex,
+ std::optional<unsigned> InRangeIndex,
ArrayRef<Value *> Idxs) {
if (Idxs.empty()) return C;
diff --git a/llvm/lib/IR/ConstantRange.cpp b/llvm/lib/IR/ConstantRange.cpp
index d443f2cb847ea..553e56597094b 100644
--- a/llvm/lib/IR/ConstantRange.cpp
+++ b/llvm/lib/IR/ConstantRange.cpp
@@ -699,7 +699,7 @@ ConstantRange ConstantRange::unionWith(const ConstantRange &CR,
return ConstantRange(std::move(L), std::move(U));
}
-Optional<ConstantRange>
+std::optional<ConstantRange>
ConstantRange::exactIntersectWith(const ConstantRange &CR) const {
// TODO: This can be implemented more efficiently.
ConstantRange Result = intersectWith(CR);
@@ -708,7 +708,7 @@ ConstantRange::exactIntersectWith(const ConstantRange &CR) const {
return std::nullopt;
}
-Optional<ConstantRange>
+std::optional<ConstantRange>
ConstantRange::exactUnionWith(const ConstantRange &CR) const {
// TODO: This can be implemented more efficiently.
ConstantRange Result = unionWith(CR);
diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp
index adbc158c8c1e3..b7126adb9f4c1 100644
--- a/llvm/lib/IR/Constants.cpp
+++ b/llvm/lib/IR/Constants.cpp
@@ -2430,7 +2430,7 @@ Constant *ConstantExpr::getSelect(Constant *C, Constant *V1, Constant *V2,
Constant *ConstantExpr::getGetElementPtr(Type *Ty, Constant *C,
ArrayRef<Value *> Idxs, bool InBounds,
- Optional<unsigned> InRangeIndex,
+ std::optional<unsigned> InRangeIndex,
Type *OnlyIfReducedTy) {
PointerType *OrigPtrTy = cast<PointerType>(C->getType()->getScalarType());
assert(Ty && "Must specify element type");
diff --git a/llvm/lib/IR/DataLayout.cpp b/llvm/lib/IR/DataLayout.cpp
index e451234eaa4d9..4bd088714d4bf 100644
--- a/llvm/lib/IR/DataLayout.cpp
+++ b/llvm/lib/IR/DataLayout.cpp
@@ -925,8 +925,8 @@ static APInt getElementIndex(TypeSize ElemSize, APInt &Offset) {
return Index;
}
-Optional<APInt> DataLayout::getGEPIndexForOffset(Type *&ElemTy,
- APInt &Offset) const {
+std::optional<APInt> DataLayout::getGEPIndexForOffset(Type *&ElemTy,
+ APInt &Offset) const {
if (auto *ArrTy = dyn_cast<ArrayType>(ElemTy)) {
ElemTy = ArrTy->getElementType();
return getElementIndex(getTypeAllocSize(ElemTy), Offset);
@@ -964,7 +964,7 @@ SmallVector<APInt> DataLayout::getGEPIndicesForOffset(Type *&ElemTy,
SmallVector<APInt> Indices;
Indices.push_back(getElementIndex(getTypeAllocSize(ElemTy), Offset));
while (Offset != 0) {
- Optional<APInt> Index = getGEPIndexForOffset(ElemTy, Offset);
+ std::optional<APInt> Index = getGEPIndexForOffset(ElemTy, Offset);
if (!Index)
break;
Indices.push_back(*Index);
diff --git a/llvm/lib/IR/Function.cpp b/llvm/lib/IR/Function.cpp
index 51ef4d0972f29..9912e1a9b7eab 100644
--- a/llvm/lib/IR/Function.cpp
+++ b/llvm/lib/IR/Function.cpp
@@ -1843,7 +1843,7 @@ bool Intrinsic::getIntrinsicSignature(Function *F,
return true;
}
-Optional<Function *> Intrinsic::remangleIntrinsicFunction(Function *F) {
+std::optional<Function *> Intrinsic::remangleIntrinsicFunction(Function *F) {
SmallVector<Type *, 4> ArgTys;
if (!getIntrinsicSignature(F, ArgTys))
return std::nullopt;
@@ -2051,7 +2051,7 @@ void Function::setEntryCount(uint64_t Count, Function::ProfileCountType Type,
setEntryCount(ProfileCount(Count, Type), Imports);
}
-Optional<ProfileCount> Function::getEntryCount(bool AllowSynthetic) const {
+std::optional<ProfileCount> Function::getEntryCount(bool AllowSynthetic) const {
MDNode *MD = getMetadata(LLVMContext::MD_prof);
if (MD && MD->getOperand(0))
if (MDString *MDS = dyn_cast<MDString>(MD->getOperand(0))) {
@@ -2091,7 +2091,7 @@ void Function::setSectionPrefix(StringRef Prefix) {
MDB.createFunctionSectionPrefix(Prefix));
}
-Optional<StringRef> Function::getSectionPrefix() const {
+std::optional<StringRef> Function::getSectionPrefix() const {
if (MDNode *MD = getMetadata(LLVMContext::MD_section_prefix)) {
assert(cast<MDString>(MD->getOperand(0))
->getString()
diff --git a/llvm/lib/IR/Globals.cpp b/llvm/lib/IR/Globals.cpp
index 7169ca2c34017..ac9b830f9952c 100644
--- a/llvm/lib/IR/Globals.cpp
+++ b/llvm/lib/IR/Globals.cpp
@@ -370,7 +370,7 @@ bool GlobalValue::isAbsoluteSymbolRef() const {
return GO->getMetadata(LLVMContext::MD_absolute_symbol);
}
-Optional<ConstantRange> GlobalValue::getAbsoluteSymbolRange() const {
+std::optional<ConstantRange> GlobalValue::getAbsoluteSymbolRange() const {
auto *GO = dyn_cast<GlobalObject>(this);
if (!GO)
return std::nullopt;
@@ -427,7 +427,7 @@ GlobalVariable::GlobalVariable(Module &M, Type *Ty, bool constant,
LinkageTypes Link, Constant *InitVal,
const Twine &Name, GlobalVariable *Before,
ThreadLocalMode TLMode,
- Optional<unsigned> AddressSpace,
+ std::optional<unsigned> AddressSpace,
bool isExternallyInitialized)
: GlobalObject(Ty, Value::GlobalVariableVal,
OperandTraits<GlobalVariable>::op_begin(this),
diff --git a/llvm/lib/IR/LLVMContext.cpp b/llvm/lib/IR/LLVMContext.cpp
index dc8671480a68b..2b5577595ee3d 100644
--- a/llvm/lib/IR/LLVMContext.cpp
+++ b/llvm/lib/IR/LLVMContext.cpp
@@ -153,7 +153,7 @@ uint64_t LLVMContext::getDiagnosticsHotnessThreshold() const {
return pImpl->DiagnosticsHotnessThreshold.value_or(UINT64_MAX);
}
void LLVMContext::setDiagnosticsMisExpectTolerance(
- Optional<uint32_t> Tolerance) {
+ std::optional<uint32_t> Tolerance) {
pImpl->DiagnosticsMisExpectTolerance = Tolerance;
}
uint32_t LLVMContext::getDiagnosticsMisExpectTolerance() const {
diff --git a/llvm/lib/IR/LLVMContextImpl.h b/llvm/lib/IR/LLVMContextImpl.h
index 469705166b435..99270daf1974c 100644
--- a/llvm/lib/IR/LLVMContextImpl.h
+++ b/llvm/lib/IR/LLVMContextImpl.h
@@ -24,7 +24,6 @@
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/FoldingSet.h"
#include "llvm/ADT/Hashing.h"
-#include "llvm/ADT/Optional.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
@@ -1389,7 +1388,7 @@ class LLVMContextImpl {
/// The percentage of
diff erence between profiling branch weights and
/// llvm.expect branch weights to tolerate when emiting MisExpect diagnostics
- Optional<uint32_t> DiagnosticsMisExpectTolerance = 0;
+ std::optional<uint32_t> DiagnosticsMisExpectTolerance = 0;
bool MisExpectWarningRequested = false;
/// The specialized remark streamer used by LLVM's OptimizationRemarkEmitter.
@@ -1421,7 +1420,7 @@ class LLVMContextImpl {
#include "llvm/IR/Metadata.def"
// Optional map for looking up composite types by identifier.
- Optional<DenseMap<const MDString *, DICompositeType *>> DITypeMap;
+ std::optional<DenseMap<const MDString *, DICompositeType *>> DITypeMap;
// MDNodes may be uniqued or not uniqued. When they're not uniqued, they
// aren't in the MDNodeSet, but they're still shared between objects, so no
@@ -1580,7 +1579,7 @@ class LLVMContextImpl {
void setOpaquePointers(bool OP);
private:
- Optional<bool> OpaquePointers;
+ std::optional<bool> OpaquePointers;
};
} // end namespace llvm
diff --git a/llvm/lib/IR/Module.cpp b/llvm/lib/IR/Module.cpp
index 1f2f86fc1e0ce..49fadc9ed7e63 100644
--- a/llvm/lib/IR/Module.cpp
+++ b/llvm/lib/IR/Module.cpp
@@ -12,7 +12,6 @@
#include "llvm/IR/Module.h"
#include "SymbolTableListTraitsImpl.h"
-#include "llvm/ADT/Optional.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringMap.h"
diff --git a/llvm/lib/IR/PassManager.cpp b/llvm/lib/IR/PassManager.cpp
index a2e9a7c625896..ef850b8235b95 100644
--- a/llvm/lib/IR/PassManager.cpp
+++ b/llvm/lib/IR/PassManager.cpp
@@ -8,7 +8,6 @@
#include "llvm/IR/PassManager.h"
#include "llvm/ADT/DenseMapInfo.h"
-#include "llvm/ADT/Optional.h"
#include "llvm/IR/PassManagerImpl.h"
#include <optional>
diff --git a/llvm/lib/IR/PseudoProbe.cpp b/llvm/lib/IR/PseudoProbe.cpp
index ae307d871f595..f3802af26a614 100644
--- a/llvm/lib/IR/PseudoProbe.cpp
+++ b/llvm/lib/IR/PseudoProbe.cpp
@@ -21,7 +21,8 @@ using namespace llvm;
namespace llvm {
-Optional<PseudoProbe> extractProbeFromDiscriminator(const Instruction &Inst) {
+std::optional<PseudoProbe>
+extractProbeFromDiscriminator(const Instruction &Inst) {
assert(isa<CallBase>(&Inst) && !isa<IntrinsicInst>(&Inst) &&
"Only call instructions should have pseudo probe encodes as their "
"Dwarf discriminators");
@@ -45,7 +46,7 @@ Optional<PseudoProbe> extractProbeFromDiscriminator(const Instruction &Inst) {
return std::nullopt;
}
-Optional<PseudoProbe> extractProbe(const Instruction &Inst) {
+std::optional<PseudoProbe> extractProbe(const Instruction &Inst) {
if (const auto *II = dyn_cast<PseudoProbeInst>(&Inst)) {
PseudoProbe Probe;
Probe.Id = II->getIndex()->getZExtValue();
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 836990030aee7..b487d24ab8daa 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -48,7 +48,6 @@
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/MapVector.h"
-#include "llvm/ADT/Optional.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallSet.h"
diff --git a/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp b/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
index e4d381509b21f..548dd06559c51 100644
--- a/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
+++ b/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
@@ -2690,7 +2690,7 @@ bool X86DAGToDAGISel::selectMOV64Imm32(SDValue N, SDValue &Imm) {
if (N->getOpcode() != ISD::TargetGlobalAddress)
return TM.getCodeModel() == CodeModel::Small;
- Optional<ConstantRange> CR =
+ std::optional<ConstantRange> CR =
cast<GlobalAddressSDNode>(N)->getGlobal()->getAbsoluteSymbolRange();
if (!CR)
return TM.getCodeModel() == CodeModel::Small;
@@ -2872,7 +2872,7 @@ bool X86DAGToDAGISel::selectRelocImm(SDValue N, SDValue &Op) {
// Check that the global's range fits into VT.
auto *GA = cast<GlobalAddressSDNode>(N.getOperand(0));
- Optional<ConstantRange> CR = GA->getGlobal()->getAbsoluteSymbolRange();
+ std::optional<ConstantRange> CR = GA->getGlobal()->getAbsoluteSymbolRange();
if (!CR || CR->getUnsignedMax().uge(1ull << VT.getSizeInBits()))
return false;
@@ -2929,7 +2929,7 @@ bool X86DAGToDAGISel::isSExtAbsoluteSymbolRef(unsigned Width, SDNode *N) const {
if (!GA)
return false;
- Optional<ConstantRange> CR = GA->getGlobal()->getAbsoluteSymbolRange();
+ std::optional<ConstantRange> CR = GA->getGlobal()->getAbsoluteSymbolRange();
if (!CR)
return Width == 32 && TM.getCodeModel() == CodeModel::Small;
diff --git a/llvm/lib/Target/X86/X86Subtarget.cpp b/llvm/lib/Target/X86/X86Subtarget.cpp
index 0d091adc8e776..e991cde5ffbfa 100644
--- a/llvm/lib/Target/X86/X86Subtarget.cpp
+++ b/llvm/lib/Target/X86/X86Subtarget.cpp
@@ -137,7 +137,7 @@ unsigned char X86Subtarget::classifyGlobalReference(const GlobalValue *GV,
// Absolute symbols can be referenced directly.
if (GV) {
- if (Optional<ConstantRange> CR = GV->getAbsoluteSymbolRange()) {
+ if (std::optional<ConstantRange> CR = GV->getAbsoluteSymbolRange()) {
// See if we can use the 8-bit immediate form. Note that some instructions
// will sign extend the immediate operand, so to be conservative we only
// accept the range [0,128).
diff --git a/llvm/lib/Transforms/IPO/SampleProfile.cpp b/llvm/lib/Transforms/IPO/SampleProfile.cpp
index deca83d4d62de..f3e8cda6642c9 100644
--- a/llvm/lib/Transforms/IPO/SampleProfile.cpp
+++ b/llvm/lib/Transforms/IPO/SampleProfile.cpp
@@ -620,7 +620,7 @@ ErrorOr<uint64_t> SampleProfileLoader::getInstWeight(const Instruction &Inst) {
ErrorOr<uint64_t> SampleProfileLoader::getProbeWeight(const Instruction &Inst) {
assert(FunctionSamples::ProfileIsProbeBased &&
"Profile is not pseudo probe based");
- Optional<PseudoProbe> Probe = extractProbe(Inst);
+ std::optional<PseudoProbe> Probe = extractProbe(Inst);
// Ignore the non-probe instruction. If none of the instruction in the BB is
// probe, we choose to infer the BB's weight.
if (!Probe)
@@ -773,7 +773,7 @@ SampleProfileLoader::findIndirectCallFunctionSamples(
const FunctionSamples *
SampleProfileLoader::findFunctionSamples(const Instruction &Inst) const {
if (FunctionSamples::ProfileIsProbeBased) {
- Optional<PseudoProbe> Probe = extractProbe(Inst);
+ std::optional<PseudoProbe> Probe = extractProbe(Inst);
if (!Probe)
return nullptr;
}
@@ -1286,7 +1286,7 @@ bool SampleProfileLoader::tryInlineCandidate(
// aggregation of duplication.
if (Candidate.CallsiteDistribution < 1) {
for (auto &I : IFI.InlinedCallSites) {
- if (Optional<PseudoProbe> Probe = extractProbe(*I))
+ if (std::optional<PseudoProbe> Probe = extractProbe(*I))
setProbeDistributionFactor(*I, Probe->Factor *
Candidate.CallsiteDistribution);
}
@@ -1311,7 +1311,7 @@ bool SampleProfileLoader::getInlineCandidate(InlineCandidate *NewCandidate,
return false;
float Factor = 1.0;
- if (Optional<PseudoProbe> Probe = extractProbe(*CB))
+ if (std::optional<PseudoProbe> Probe = extractProbe(*CB))
Factor = Probe->Factor;
uint64_t CallsiteCount =
@@ -1636,7 +1636,7 @@ void SampleProfileLoader::generateMDProfMetadata(Function &F) {
// Prorate the callsite counts based on the pre-ICP distribution
// factor to reflect what is already done to the callsite before
// ICP, such as calliste cloning.
- if (Optional<PseudoProbe> Probe = extractProbe(I)) {
+ if (std::optional<PseudoProbe> Probe = extractProbe(I)) {
if (Probe->Factor < 1)
T = SampleRecord::adjustCallTargets(T.get(), Probe->Factor);
}
diff --git a/llvm/lib/Transforms/IPO/SampleProfileProbe.cpp b/llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
index d1ab2649ee2ee..d1edea9cba770 100644
--- a/llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
+++ b/llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
@@ -137,7 +137,7 @@ void PseudoProbeVerifier::runAfterPass(const Loop *L) {
void PseudoProbeVerifier::collectProbeFactors(const BasicBlock *Block,
ProbeFactorMap &ProbeFactors) {
for (const auto &I : *Block) {
- if (Optional<PseudoProbe> Probe = extractProbe(I)) {
+ if (std::optional<PseudoProbe> Probe = extractProbe(I)) {
uint64_t Hash = computeCallStackHash(I);
ProbeFactors[{Probe->Id, Hash}] += Probe->Factor;
}
@@ -421,7 +421,7 @@ void PseudoProbeUpdatePass::runOnFunction(Function &F,
ProbeFactorMap ProbeFactors;
for (auto &Block : F) {
for (auto &I : Block) {
- if (Optional<PseudoProbe> Probe = extractProbe(I)) {
+ if (std::optional<PseudoProbe> Probe = extractProbe(I)) {
uint64_t Hash = computeCallStackHash(I);
ProbeFactors[{Probe->Id, Hash}] += BBProfileCount(&Block);
}
@@ -431,7 +431,7 @@ void PseudoProbeUpdatePass::runOnFunction(Function &F,
// Fix up over-counted probes.
for (auto &Block : F) {
for (auto &I : Block) {
- if (Optional<PseudoProbe> Probe = extractProbe(I)) {
+ if (std::optional<PseudoProbe> Probe = extractProbe(I)) {
uint64_t Hash = computeCallStackHash(I);
float Sum = ProbeFactors[{Probe->Id, Hash}];
if (Sum != 0)
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
index 39b4af5e97399..032021b5806b5 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
@@ -1174,7 +1174,7 @@ Value *InstCombinerImpl::foldAndOrOfICmpsUsingRanges(ICmpInst *ICmp1,
Type *Ty = V1->getType();
Value *NewV = V1;
- Optional<ConstantRange> CR = CR1.exactUnionWith(CR2);
+ std::optional<ConstantRange> CR = CR1.exactUnionWith(CR2);
if (!CR) {
if (!(ICmp1->hasOneUse() && ICmp2->hasOneUse()) || CR1.isWrappedSet() ||
CR2.isWrappedSet())
diff --git a/llvm/lib/Transforms/Scalar/GuardWidening.cpp b/llvm/lib/Transforms/Scalar/GuardWidening.cpp
index 6f0349fc7bf49..abe0babc3f123 100644
--- a/llvm/lib/Transforms/Scalar/GuardWidening.cpp
+++ b/llvm/lib/Transforms/Scalar/GuardWidening.cpp
@@ -524,7 +524,8 @@ bool GuardWideningImpl::widenCondCommon(Value *Cond0, Value *Cond1,
// Given what we're doing here and the semantics of guards, it would
// be correct to use a subset intersection, but that may be too
// aggressive in cases we care about.
- if (Optional<ConstantRange> Intersect = CR0.exactIntersectWith(CR1)) {
+ if (std::optional<ConstantRange> Intersect =
+ CR0.exactIntersectWith(CR1)) {
APInt NewRHSAP;
CmpInst::Predicate Pred;
if (Intersect->getEquivalentICmp(Pred, NewRHSAP)) {
diff --git a/llvm/lib/Transforms/Utils/Evaluator.cpp b/llvm/lib/Transforms/Utils/Evaluator.cpp
index 65d065af99b69..dc58bebd724b0 100644
--- a/llvm/lib/Transforms/Utils/Evaluator.cpp
+++ b/llvm/lib/Transforms/Utils/Evaluator.cpp
@@ -132,7 +132,7 @@ Constant *Evaluator::MutableValue::read(Type *Ty, APInt Offset,
const MutableValue *V = this;
while (const auto *Agg = V->Val.dyn_cast<MutableAggregate *>()) {
Type *AggTy = Agg->Ty;
- Optional<APInt> Index = DL.getGEPIndexForOffset(AggTy, Offset);
+ std::optional<APInt> Index = DL.getGEPIndexForOffset(AggTy, Offset);
if (!Index || Index->uge(Agg->Elements.size()) ||
!TypeSize::isKnownLE(TySize, DL.getTypeStoreSize(AggTy)))
return nullptr;
@@ -176,7 +176,7 @@ bool Evaluator::MutableValue::write(Constant *V, APInt Offset,
MutableAggregate *Agg = MV->Val.get<MutableAggregate *>();
Type *AggTy = Agg->Ty;
- Optional<APInt> Index = DL.getGEPIndexForOffset(AggTy, Offset);
+ std::optional<APInt> Index = DL.getGEPIndexForOffset(AggTy, Offset);
if (!Index || Index->uge(Agg->Elements.size()) ||
!TypeSize::isKnownLE(TySize, DL.getTypeStoreSize(AggTy)))
return false;
diff --git a/llvm/lib/Transforms/Utils/ValueMapper.cpp b/llvm/lib/Transforms/Utils/ValueMapper.cpp
index 8b3ffb1d8cebb..f20f2810f3fd1 100644
--- a/llvm/lib/Transforms/Utils/ValueMapper.cpp
+++ b/llvm/lib/Transforms/Utils/ValueMapper.cpp
@@ -611,7 +611,7 @@ Optional<Metadata *> MDNodeMapper::getMappedOp(const Metadata *Op) const {
if (!Op)
return nullptr;
- if (Optional<Metadata *> MappedOp = M.getVM().getMappedMD(Op))
+ if (std::optional<Metadata *> MappedOp = M.getVM().getMappedMD(Op))
return *MappedOp;
if (isa<MDString>(Op))
@@ -828,7 +828,7 @@ Metadata *MDNodeMapper::mapTopLevelUniquedNode(const MDNode &FirstN) {
Optional<Metadata *> Mapper::mapSimpleMetadata(const Metadata *MD) {
// If the value already exists in the map, use it.
- if (Optional<Metadata *> NewMD = getVM().getMappedMD(MD))
+ if (std::optional<Metadata *> NewMD = getVM().getMappedMD(MD))
return *NewMD;
if (isa<MDString>(MD))
diff --git a/llvm/tools/llvm-reduce/ReducerWorkItem.cpp b/llvm/tools/llvm-reduce/ReducerWorkItem.cpp
index ea5284a67cefb..b536c98bea93b 100644
--- a/llvm/tools/llvm-reduce/ReducerWorkItem.cpp
+++ b/llvm/tools/llvm-reduce/ReducerWorkItem.cpp
@@ -238,7 +238,7 @@ static std::unique_ptr<MachineFunction> cloneMF(MachineFunction *SrcMF,
SrcMBB.isInlineAsmBrIndirectTarget());
// FIXME: This is not serialized
- if (Optional<uint64_t> Weight = SrcMBB.getIrrLoopHeaderWeight())
+ if (std::optional<uint64_t> Weight = SrcMBB.getIrrLoopHeaderWeight())
DstMBB->setIrrLoopHeaderWeight(*Weight);
}
diff --git a/llvm/unittests/IR/ConstantRangeTest.cpp b/llvm/unittests/IR/ConstantRangeTest.cpp
index ab55b7f0545d5..1427a6c3aa9d9 100644
--- a/llvm/unittests/IR/ConstantRangeTest.cpp
+++ b/llvm/unittests/IR/ConstantRangeTest.cpp
@@ -554,7 +554,7 @@ void testBinarySetOperationExhaustive(Fn1 OpFn, Fn2 ExactOpFn, Fn3 InResultFn) {
ConstantRange SignedCR = OpFn(CR1, CR2, ConstantRange::Signed);
TestRange(SignedCR, Elems, PreferSmallestNonFullSigned, {CR1, CR2});
- Optional<ConstantRange> ExactCR = ExactOpFn(CR1, CR2);
+ std::optional<ConstantRange> ExactCR = ExactOpFn(CR1, CR2);
if (SmallestCR.isSizeLargerThan(Elems.count())) {
EXPECT_TRUE(!ExactCR);
} else {
More information about the cfe-commits
mailing list