[llvm] da2f5d0 - [tools] llvm::Optional => std::optional

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 14 00:01:11 PST 2022


Author: Fangrui Song
Date: 2022-12-14T08:01:04Z
New Revision: da2f5d0a410bd4188792980739ca49f4169b8bd4

URL: https://github.com/llvm/llvm-project/commit/da2f5d0a410bd4188792980739ca49f4169b8bd4
DIFF: https://github.com/llvm/llvm-project/commit/da2f5d0a410bd4188792980739ca49f4169b8bd4.diff

LOG: [tools] llvm::Optional => std::optional

Added: 
    

Modified: 
    llvm/tools/dsymutil/DwarfLinkerForBinary.cpp
    llvm/tools/dsymutil/LinkUtils.h
    llvm/tools/dsymutil/dsymutil.cpp
    llvm/tools/llvm-cov/CodeCoverage.cpp
    llvm/tools/llvm-dwarfutil/DebugInfoLinker.cpp
    llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
    llvm/tools/llvm-exegesis/lib/MCInstrDescView.h
    llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp
    llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
    llvm/tools/llvm-mca/Views/InstructionInfoView.h
    llvm/tools/llvm-nm/llvm-nm.cpp
    llvm/tools/llvm-pdbutil/ExplainOutputStyle.cpp
    llvm/tools/llvm-pdbutil/ExplainOutputStyle.h
    llvm/tools/llvm-pdbutil/StreamUtil.h
    llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp
    llvm/tools/llvm-pdbutil/llvm-pdbutil.h
    llvm/tools/llvm-profgen/PerfReader.cpp
    llvm/tools/llvm-profgen/PerfReader.h
    llvm/tools/llvm-profgen/ProfiledBinary.h
    llvm/tools/llvm-profgen/llvm-profgen.cpp
    llvm/tools/llvm-rc/ResourceFileWriter.h
    llvm/tools/llvm-rc/ResourceScriptParser.cpp
    llvm/tools/llvm-rc/ResourceScriptStmt.h
    llvm/tools/llvm-sim/llvm-sim.cpp
    llvm/tools/llvm-xray/xray-account.h

Removed: 
    


################################################################################
diff  --git a/llvm/tools/dsymutil/DwarfLinkerForBinary.cpp b/llvm/tools/dsymutil/DwarfLinkerForBinary.cpp
index 16e608bf81c3e..14551b038e8cd 100644
--- a/llvm/tools/dsymutil/DwarfLinkerForBinary.cpp
+++ b/llvm/tools/dsymutil/DwarfLinkerForBinary.cpp
@@ -410,7 +410,7 @@ void DwarfLinkerForBinary::collectRelocationsToApplyToSwiftReflectionSections(
     }
 
     auto CalculateAddressOfSymbolInDwarfSegment =
-        [&]() -> llvm::Optional<int64_t> {
+        [&]() -> std::optional<int64_t> {
       auto Symbol = It->getSymbol();
       auto SymbolAbsoluteAddress = Symbol->getAddress();
       if (!SymbolAbsoluteAddress)
@@ -446,7 +446,7 @@ void DwarfLinkerForBinary::collectRelocationsToApplyToSwiftReflectionSections(
 
     bool ShouldSubtractDwarfVM = false;
     // For the second symbol there are two possibilities.
-    llvm::Optional<int64_t> SecondSymbolAddress;
+    std::optional<int64_t> SecondSymbolAddress;
     auto Sym = It->getSymbol();
     if (Sym != MO->symbol_end()) {
       Expected<StringRef> SymbolName = Sym->getName();

diff  --git a/llvm/tools/dsymutil/LinkUtils.h b/llvm/tools/dsymutil/LinkUtils.h
index da21d9bc94e71..f08d92300e3a5 100644
--- a/llvm/tools/dsymutil/LinkUtils.h
+++ b/llvm/tools/dsymutil/LinkUtils.h
@@ -73,7 +73,7 @@ struct LinkOptions {
   std::map<std::string, std::string> ObjectPrefixMap;
 
   /// The Resources directory in the .dSYM bundle.
-  Optional<std::string> ResourceDir;
+  std::optional<std::string> ResourceDir;
 
   /// Symbol map translator.
   SymbolMapTranslator Translator;

diff  --git a/llvm/tools/dsymutil/dsymutil.cpp b/llvm/tools/dsymutil/dsymutil.cpp
index 2a05321075853..5ed3b2bf609fa 100644
--- a/llvm/tools/dsymutil/dsymutil.cpp
+++ b/llvm/tools/dsymutil/dsymutil.cpp
@@ -485,12 +485,13 @@ static bool verifyOutput(StringRef OutputFile, StringRef Arch, bool Verbose) {
 
 namespace {
 struct OutputLocation {
-  OutputLocation(std::string DWARFFile, Optional<std::string> ResourceDir = {})
+  OutputLocation(std::string DWARFFile,
+                 std::optional<std::string> ResourceDir = {})
       : DWARFFile(DWARFFile), ResourceDir(ResourceDir) {}
   /// This method is a workaround for older compilers.
-  Optional<std::string> getResourceDir() const { return ResourceDir; }
+  std::optional<std::string> getResourceDir() const { return ResourceDir; }
   std::string DWARFFile;
-  Optional<std::string> ResourceDir;
+  std::optional<std::string> ResourceDir;
 };
 } // namespace
 

diff  --git a/llvm/tools/llvm-cov/CodeCoverage.cpp b/llvm/tools/llvm-cov/CodeCoverage.cpp
index d2dfbc28d14b5..6010362e46ec3 100644
--- a/llvm/tools/llvm-cov/CodeCoverage.cpp
+++ b/llvm/tools/llvm-cov/CodeCoverage.cpp
@@ -85,7 +85,7 @@ class CodeCoverageTool {
   bool isEquivalentFile(StringRef FilePath1, StringRef FilePath2);
 
   /// Retrieve a file status with a cache.
-  Optional<sys::fs::file_status> getFileStatus(StringRef FilePath);
+  std::optional<sys::fs::file_status> getFileStatus(StringRef FilePath);
 
   /// Return a memory buffer for the given source file.
   ErrorOr<const MemoryBuffer &> getSourceFile(StringRef SourceFile);
@@ -161,7 +161,7 @@ class CodeCoverageTool {
   std::optional<std::pair<std::string, std::string>> PathRemapping;
 
   /// File status cache used when finding the same file.
-  StringMap<Optional<sys::fs::file_status>> FileStatusCache;
+  StringMap<std::optional<sys::fs::file_status>> FileStatusCache;
 
   /// The architecture the coverage mapping data targets.
   std::vector<StringRef> CoverageArches;
@@ -249,7 +249,7 @@ void CodeCoverageTool::collectPaths(const std::string &Path) {
   }
 }
 
-Optional<sys::fs::file_status>
+std::optional<sys::fs::file_status>
 CodeCoverageTool::getFileStatus(StringRef FilePath) {
   auto It = FileStatusCache.try_emplace(FilePath);
   auto &CachedStatus = It.first->getValue();

diff  --git a/llvm/tools/llvm-dwarfutil/DebugInfoLinker.cpp b/llvm/tools/llvm-dwarfutil/DebugInfoLinker.cpp
index 4902f083a6935..adf48cd87e0d9 100644
--- a/llvm/tools/llvm-dwarfutil/DebugInfoLinker.cpp
+++ b/llvm/tools/llvm-dwarfutil/DebugInfoLinker.cpp
@@ -166,7 +166,7 @@ class ObjFileAddressMap : public AddressesMap {
   // returns true if specified address range is inside address ranges
   // of executable sections.
   bool isInsideExecutableSectionsAddressRange(uint64_t LowPC,
-                                              Optional<uint64_t> HighPC) {
+                                              std::optional<uint64_t> HighPC) {
     std::optional<AddressRange> Range =
         TextAddressRanges.getRangeThatContains(LowPC);
 
@@ -176,7 +176,7 @@ class ObjFileAddressMap : public AddressesMap {
     return Range.has_value();
   }
 
-  uint64_t isBFDDeadAddressRange(uint64_t LowPC, Optional<uint64_t> HighPC,
+  uint64_t isBFDDeadAddressRange(uint64_t LowPC, std::optional<uint64_t> HighPC,
                                  uint16_t Version) {
     if (LowPC == 0)
       return true;
@@ -187,7 +187,8 @@ class ObjFileAddressMap : public AddressesMap {
     return !isInsideExecutableSectionsAddressRange(LowPC, HighPC);
   }
 
-  uint64_t isMAXPCDeadAddressRange(uint64_t LowPC, Optional<uint64_t> HighPC,
+  uint64_t isMAXPCDeadAddressRange(uint64_t LowPC,
+                                   std::optional<uint64_t> HighPC,
                                    uint16_t Version, uint8_t AddressByteSize) {
     if (Version <= 4 && HighPC) {
       if (LowPC == (dwarf::computeTombstoneAddress(AddressByteSize) - 1))
@@ -202,7 +203,7 @@ class ObjFileAddressMap : public AddressesMap {
     return false;
   }
 
-  bool isDeadAddressRange(uint64_t LowPC, Optional<uint64_t> HighPC,
+  bool isDeadAddressRange(uint64_t LowPC, std::optional<uint64_t> HighPC,
                           uint16_t Version, TombstoneKind Tombstone,
                           uint8_t AddressByteSize) {
     switch (Tombstone) {

diff  --git a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
index 81adaf02ec06e..3972bb3e2a103 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
@@ -75,7 +75,7 @@ struct YamlContext {
     return RegName;
   }
 
-  Optional<unsigned> getRegNo(StringRef RegName) {
+  std::optional<unsigned> getRegNo(StringRef RegName) {
     auto Iter = RegNameToRegNo.find(RegName);
     if (Iter != RegNameToRegNo.end())
       return Iter->second;
@@ -242,7 +242,7 @@ template <> struct ScalarTraits<exegesis::RegisterValue> {
     String.split(Pieces, "=0x", /* MaxSplit */ -1,
                  /* KeepEmpty */ false);
     YamlContext &Context = getTypedContext(Ctx);
-    Optional<unsigned> RegNo;
+    std::optional<unsigned> RegNo;
     if (Pieces.size() == 2 && (RegNo = Context.getRegNo(Pieces[0]))) {
       RV.Register = *RegNo;
       const unsigned BitsNeeded = APInt::getBitsNeeded(Pieces[1], kRadix);

diff  --git a/llvm/tools/llvm-exegesis/lib/MCInstrDescView.h b/llvm/tools/llvm-exegesis/lib/MCInstrDescView.h
index 8c7e0b2e01d34..8dd2c56ee3eb7 100644
--- a/llvm/tools/llvm-exegesis/lib/MCInstrDescView.h
+++ b/llvm/tools/llvm-exegesis/lib/MCInstrDescView.h
@@ -49,7 +49,7 @@ struct Variable {
 
   // The index of this Variable in Instruction.Variables and its associated
   // Value in InstructionBuilder.VariableValues.
-  Optional<uint8_t> Index;
+  std::optional<uint8_t> Index;
 };
 
 // MCOperandInfo can only represents Explicit operands. This object gives a
@@ -82,13 +82,13 @@ struct Operand {
   const MCOperandInfo &getExplicitOperandInfo() const;
 
   // Please use the accessors above and not the following fields.
-  Optional<uint8_t> Index;
+  std::optional<uint8_t> Index;
   bool IsDef = false;
   const RegisterAliasingTracker *Tracker = nullptr; // Set for Register Op.
   const MCOperandInfo *Info = nullptr;              // Set for Explicit Op.
-  Optional<uint8_t> TiedToIndex;                    // Set for Reg&Explicit Op.
+  std::optional<uint8_t> TiedToIndex;               // Set for Reg&Explicit Op.
   const MCPhysReg *ImplicitReg = nullptr;           // Set for Implicit Op.
-  Optional<uint8_t> VariableIndex;                  // Set for Explicit Op.
+  std::optional<uint8_t> VariableIndex;             // Set for Explicit Op.
 };
 
 /// A cache of BitVector to reuse between Instructions.

diff  --git a/llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp b/llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp
index d409493ce07e7..ac16ae8b5b7c6 100644
--- a/llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp
+++ b/llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp
@@ -187,7 +187,7 @@ static bool filterArch(MachOObjectFile &Obj) {
 ///
 /// \returns A valid image base address if we are able to extract one.
 template <class ELFT>
-static llvm::Optional<uint64_t>
+static std::optional<uint64_t>
 getImageBaseAddress(const object::ELFFile<ELFT> &ELFFile) {
   auto PhdrRangeOrErr = ELFFile.program_headers();
   if (!PhdrRangeOrErr) {
@@ -208,7 +208,7 @@ getImageBaseAddress(const object::ELFFile<ELFT> &ELFFile) {
 /// \param MachO A mach-o object file we will search.
 ///
 /// \returns A valid image base address if we are able to extract one.
-static llvm::Optional<uint64_t>
+static std::optional<uint64_t>
 getImageBaseAddress(const object::MachOObjectFile *MachO) {
   for (const auto &Command : MachO->load_commands()) {
     if (Command.C.cmd == MachO::LC_SEGMENT) {
@@ -238,7 +238,7 @@ getImageBaseAddress(const object::MachOObjectFile *MachO) {
 /// \param Obj An object file we will search.
 ///
 /// \returns A valid image base address if we are able to extract one.
-static llvm::Optional<uint64_t> getImageBaseAddress(object::ObjectFile &Obj) {
+static std::optional<uint64_t> getImageBaseAddress(object::ObjectFile &Obj) {
   if (const auto *MachO = dyn_cast<object::MachOObjectFile>(&Obj))
     return getImageBaseAddress(MachO);
   else if (const auto *ELFObj = dyn_cast<object::ELF32LEObjectFile>(&Obj))

diff  --git a/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp b/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
index 9870bf25f13f6..3357afb0735a7 100644
--- a/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
+++ b/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
@@ -126,7 +126,8 @@ struct Config {
 
 static Expected<std::string> searchForFile(const Twine &FileName) {
   auto FindLib =
-      [FileName](ArrayRef<std::string> SearchDirs) -> Optional<std::string> {
+      [FileName](
+          ArrayRef<std::string> SearchDirs) -> std::optional<std::string> {
     for (StringRef Dir : SearchDirs) {
       SmallString<128> Path;
       sys::path::append(Path, Dir, FileName);
@@ -139,7 +140,7 @@ static Expected<std::string> searchForFile(const Twine &FileName) {
     return std::nullopt;
   };
 
-  Optional<std::string> Found = FindLib(LibrarySearchDirs);
+  std::optional<std::string> Found = FindLib(LibrarySearchDirs);
   if (!Found)
     Found = FindLib(StandardSearchDirs);
   if (Found)

diff  --git a/llvm/tools/llvm-mca/Views/InstructionInfoView.h b/llvm/tools/llvm-mca/Views/InstructionInfoView.h
index c35d316775f4b..bddd01a086b58 100644
--- a/llvm/tools/llvm-mca/Views/InstructionInfoView.h
+++ b/llvm/tools/llvm-mca/Views/InstructionInfoView.h
@@ -61,7 +61,7 @@ class InstructionInfoView : public InstructionView {
   struct InstructionInfoViewData {
     unsigned NumMicroOpcodes = 0;
     unsigned Latency = 0;
-    Optional<double> RThroughput = 0.0;
+    std::optional<double> RThroughput = 0.0;
     bool mayLoad = false;
     bool mayStore = false;
     bool hasUnmodeledSideEffects = false;

diff  --git a/llvm/tools/llvm-nm/llvm-nm.cpp b/llvm/tools/llvm-nm/llvm-nm.cpp
index 0d30268d72117..47644f07fd82d 100644
--- a/llvm/tools/llvm-nm/llvm-nm.cpp
+++ b/llvm/tools/llvm-nm/llvm-nm.cpp
@@ -647,25 +647,25 @@ static void darwinPrintStab(MachOObjectFile *MachO, const NMSymbol &S) {
     outs() << format("   %02x", NType);
 }
 
-static Optional<std::string> demangle(StringRef Name) {
+static std::optional<std::string> demangle(StringRef Name) {
   std::string Demangled;
   if (nonMicrosoftDemangle(Name.str().c_str(), Demangled))
     return Demangled;
   return std::nullopt;
 }
 
-static Optional<std::string> demangleXCOFF(StringRef Name) {
+static std::optional<std::string> demangleXCOFF(StringRef Name) {
   if (Name.empty() || Name[0] != '.')
     return demangle(Name);
 
   Name = Name.drop_front();
-  Optional<std::string> DemangledName = demangle(Name);
+  std::optional<std::string> DemangledName = demangle(Name);
   if (DemangledName)
     return "." + *DemangledName;
   return std::nullopt;
 }
 
-static Optional<std::string> demangleMachO(StringRef Name) {
+static std::optional<std::string> demangleMachO(StringRef Name) {
   if (!Name.empty() && Name[0] == '_')
     Name = Name.drop_front();
   return demangle(Name);
@@ -762,12 +762,12 @@ static void printSymbolList(SymbolicFile &Obj,
     std::string Name = S.Name;
     MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(&Obj);
     if (Demangle) {
-      function_ref<Optional<std::string>(StringRef)> Fn = ::demangle;
+      function_ref<std::optional<std::string>(StringRef)> Fn = ::demangle;
       if (Obj.isXCOFF())
         Fn = demangleXCOFF;
       if (Obj.isMachO())
         Fn = demangleMachO;
-      if (Optional<std::string> Opt = Fn(S.Name))
+      if (std::optional<std::string> Opt = Fn(S.Name))
         Name = *Opt;
     }
 

diff  --git a/llvm/tools/llvm-pdbutil/ExplainOutputStyle.cpp b/llvm/tools/llvm-pdbutil/ExplainOutputStyle.cpp
index ef9eb29fd6e60..3e57e318d7e05 100644
--- a/llvm/tools/llvm-pdbutil/ExplainOutputStyle.cpp
+++ b/llvm/tools/llvm-pdbutil/ExplainOutputStyle.cpp
@@ -124,7 +124,7 @@ bool ExplainOutputStyle::isPdbStreamDirectoryBlock() const {
   return llvm::is_contained(Layout.DirectoryBlocks, pdbBlockIndex());
 }
 
-Optional<uint32_t> ExplainOutputStyle::getPdbBlockStreamIndex() const {
+std::optional<uint32_t> ExplainOutputStyle::getPdbBlockStreamIndex() const {
   const auto &Layout = File.pdb().getMsfLayout();
   for (const auto &Entry : enumerate(Layout.StreamMap)) {
     if (!llvm::is_contained(Entry.value(), pdbBlockIndex()))

diff  --git a/llvm/tools/llvm-pdbutil/ExplainOutputStyle.h b/llvm/tools/llvm-pdbutil/ExplainOutputStyle.h
index e3d19f25a9eac..499f2a8648e0b 100644
--- a/llvm/tools/llvm-pdbutil/ExplainOutputStyle.h
+++ b/llvm/tools/llvm-pdbutil/ExplainOutputStyle.h
@@ -43,7 +43,7 @@ class ExplainOutputStyle : public OutputStyle {
   bool isPdbFpmBlock() const;
   bool isPdbBlockMapBlock() const;
   bool isPdbStreamDirectoryBlock() const;
-  Optional<uint32_t> getPdbBlockStreamIndex() const;
+  std::optional<uint32_t> getPdbBlockStreamIndex() const;
 
   void explainPdbSuperBlockOffset();
   void explainPdbFpmBlockOffset();

diff  --git a/llvm/tools/llvm-pdbutil/StreamUtil.h b/llvm/tools/llvm-pdbutil/StreamUtil.h
index f810f7dc15b4c..9d9c5f9a9a634 100644
--- a/llvm/tools/llvm-pdbutil/StreamUtil.h
+++ b/llvm/tools/llvm-pdbutil/StreamUtil.h
@@ -52,7 +52,7 @@ struct StreamInfo {
   StreamPurpose Purpose;
   uint32_t StreamIndex;
   std::string Name;
-  Optional<uint32_t> ModuleIndex;
+  std::optional<uint32_t> ModuleIndex;
 };
 
 void discoverStreamPurposes(PDBFile &File,

diff  --git a/llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp b/llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp
index 214cc07a7e93b..61cad15e8b925 100644
--- a/llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp
+++ b/llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp
@@ -377,8 +377,8 @@ cl::OptionCategory PdbBytes("PDB Stream Options");
 cl::OptionCategory Types("Type Options");
 cl::OptionCategory ModuleCategory("Module Options");
 
-llvm::Optional<NumberRange> DumpBlockRange;
-llvm::Optional<NumberRange> DumpByteRange;
+std::optional<NumberRange> DumpBlockRange;
+std::optional<NumberRange> DumpByteRange;
 
 cl::opt<std::string> DumpBlockRangeOpt(
     "block-range", cl::value_desc("start[-end]"),
@@ -1422,7 +1422,7 @@ static void exportStream() {
 }
 
 static bool parseRange(StringRef Str,
-                       Optional<opts::bytes::NumberRange> &Parsed) {
+                       std::optional<opts::bytes::NumberRange> &Parsed) {
   if (Str.empty())
     return true;
 

diff  --git a/llvm/tools/llvm-pdbutil/llvm-pdbutil.h b/llvm/tools/llvm-pdbutil/llvm-pdbutil.h
index 455fe5f281915..efda550e17b03 100644
--- a/llvm/tools/llvm-pdbutil/llvm-pdbutil.h
+++ b/llvm/tools/llvm-pdbutil/llvm-pdbutil.h
@@ -111,11 +111,11 @@ extern llvm::cl::opt<uint32_t> ClassRecursionDepth;
 namespace bytes {
 struct NumberRange {
   uint64_t Min;
-  llvm::Optional<uint64_t> Max;
+  std::optional<uint64_t> Max;
 };
 
-extern llvm::Optional<NumberRange> DumpBlockRange;
-extern llvm::Optional<NumberRange> DumpByteRange;
+extern std::optional<NumberRange> DumpBlockRange;
+extern std::optional<NumberRange> DumpByteRange;
 extern llvm::cl::list<std::string> DumpStreamData;
 extern llvm::cl::opt<bool> NameMap;
 extern llvm::cl::opt<bool> Fpm;

diff  --git a/llvm/tools/llvm-profgen/PerfReader.cpp b/llvm/tools/llvm-profgen/PerfReader.cpp
index 14bc04b0543a0..86c0131e10102 100644
--- a/llvm/tools/llvm-profgen/PerfReader.cpp
+++ b/llvm/tools/llvm-profgen/PerfReader.cpp
@@ -319,7 +319,7 @@ bool VirtualUnwinder::unwind(const PerfSample *Sample, uint64_t Repeat) {
 
 std::unique_ptr<PerfReaderBase>
 PerfReaderBase::create(ProfiledBinary *Binary, PerfInputFile &PerfInput,
-                       Optional<uint32_t> PIDFilter) {
+                       std::optional<uint32_t> PIDFilter) {
   std::unique_ptr<PerfReaderBase> PerfReader;
 
   if (PerfInput.Format == PerfFormat::UnsymbolizedProfile) {
@@ -350,8 +350,10 @@ PerfReaderBase::create(ProfiledBinary *Binary, PerfInputFile &PerfInput,
   return PerfReader;
 }
 
-PerfInputFile PerfScriptReader::convertPerfDataToTrace(
-    ProfiledBinary *Binary, PerfInputFile &File, Optional<uint32_t> PIDFilter) {
+PerfInputFile
+PerfScriptReader::convertPerfDataToTrace(ProfiledBinary *Binary,
+                                         PerfInputFile &File,
+                                         std::optional<uint32_t> PIDFilter) {
   StringRef PerfData = File.InputFile;
   // Run perf script to retrieve PIDs matching binary we're interested in.
   auto PerfExecutable = sys::Process::FindInEnvPath("PATH", "perf");

diff  --git a/llvm/tools/llvm-profgen/PerfReader.h b/llvm/tools/llvm-profgen/PerfReader.h
index 5accea0863980..14137e82572d7 100644
--- a/llvm/tools/llvm-profgen/PerfReader.h
+++ b/llvm/tools/llvm-profgen/PerfReader.h
@@ -567,9 +567,9 @@ class PerfReaderBase {
     Binary->setBaseAddress(Binary->getPreferredBaseAddress());
   };
   virtual ~PerfReaderBase() = default;
-  static std::unique_ptr<PerfReaderBase> create(ProfiledBinary *Binary,
-                                                PerfInputFile &PerfInput,
-                                                Optional<uint32_t> PIDFilter);
+  static std::unique_ptr<PerfReaderBase>
+  create(ProfiledBinary *Binary, PerfInputFile &PerfInput,
+         std::optional<uint32_t> PIDFilter);
 
   // Entry of the reader to parse multiple perf traces
   virtual void parsePerfTraces() = 0;
@@ -594,15 +594,15 @@ class PerfReaderBase {
 class PerfScriptReader : public PerfReaderBase {
 public:
   PerfScriptReader(ProfiledBinary *B, StringRef PerfTrace,
-                   Optional<uint32_t> PID)
+                   std::optional<uint32_t> PID)
       : PerfReaderBase(B, PerfTrace), PIDFilter(PID){};
 
   // Entry of the reader to parse multiple perf traces
   void parsePerfTraces() override;
   // Generate perf script from perf data
-  static PerfInputFile convertPerfDataToTrace(ProfiledBinary *Binary,
-                                              PerfInputFile &File,
-                                              Optional<uint32_t> PIDFilter);
+  static PerfInputFile
+  convertPerfDataToTrace(ProfiledBinary *Binary, PerfInputFile &File,
+                         std::optional<uint32_t> PIDFilter);
   // Extract perf script type by peaking at the input
   static PerfContent checkPerfScriptType(StringRef FileName);
 
@@ -663,7 +663,7 @@ class PerfScriptReader : public PerfReaderBase {
   // Keep track of all invalid return addresses
   std::set<uint64_t> InvalidReturnAddresses;
   // PID for the process of interest
-  Optional<uint32_t> PIDFilter;
+  std::optional<uint32_t> PIDFilter;
 };
 
 /*
@@ -675,7 +675,7 @@ class PerfScriptReader : public PerfReaderBase {
 class LBRPerfReader : public PerfScriptReader {
 public:
   LBRPerfReader(ProfiledBinary *Binary, StringRef PerfTrace,
-                Optional<uint32_t> PID)
+                std::optional<uint32_t> PID)
       : PerfScriptReader(Binary, PerfTrace, PID){};
   // Parse the LBR only sample.
   void parseSample(TraceStream &TraceIt, uint64_t Count) override;
@@ -693,7 +693,7 @@ class LBRPerfReader : public PerfScriptReader {
 class HybridPerfReader : public PerfScriptReader {
 public:
   HybridPerfReader(ProfiledBinary *Binary, StringRef PerfTrace,
-                   Optional<uint32_t> PID)
+                   std::optional<uint32_t> PID)
       : PerfScriptReader(Binary, PerfTrace, PID){};
   // Parse the hybrid sample including the call and LBR line
   void parseSample(TraceStream &TraceIt, uint64_t Count) override;

diff  --git a/llvm/tools/llvm-profgen/ProfiledBinary.h b/llvm/tools/llvm-profgen/ProfiledBinary.h
index 29206b1c2a93c..61f9942762890 100644
--- a/llvm/tools/llvm-profgen/ProfiledBinary.h
+++ b/llvm/tools/llvm-profgen/ProfiledBinary.h
@@ -506,7 +506,7 @@ class ProfiledBinary {
     return I.first->second;
   }
 
-  Optional<SampleContextFrame> getInlineLeafFrameLoc(uint64_t Address) {
+  std::optional<SampleContextFrame> getInlineLeafFrameLoc(uint64_t Address) {
     const auto &Stack = getCachedFrameLocationStack(Address);
     if (Stack.empty())
       return {};

diff  --git a/llvm/tools/llvm-profgen/llvm-profgen.cpp b/llvm/tools/llvm-profgen/llvm-profgen.cpp
index 7d83655ac62f6..596882c1b93fa 100644
--- a/llvm/tools/llvm-profgen/llvm-profgen.cpp
+++ b/llvm/tools/llvm-profgen/llvm-profgen.cpp
@@ -167,7 +167,7 @@ int main(int argc, const char *argv[]) {
     Generator->generateProfile();
     Generator->write();
   } else {
-    Optional<uint32_t> PIDFilter;
+    std::optional<uint32_t> PIDFilter;
     if (ProcessId.getNumOccurrences())
       PIDFilter = ProcessId;
     PerfInputFile PerfFile = getPerfInputFile();

diff  --git a/llvm/tools/llvm-rc/ResourceFileWriter.h b/llvm/tools/llvm-rc/ResourceFileWriter.h
index 0f3d5937259f8..7a92f84d5d84f 100644
--- a/llvm/tools/llvm-rc/ResourceFileWriter.h
+++ b/llvm/tools/llvm-rc/ResourceFileWriter.h
@@ -79,8 +79,8 @@ class ResourceFileWriter : public Visitor {
     uint32_t Characteristics;
     uint32_t VersionInfo;
 
-    Optional<uint32_t> Style;
-    Optional<uint32_t> ExStyle;
+    std::optional<uint32_t> Style;
+    std::optional<uint32_t> ExStyle;
     StringRef Caption;
     struct FontInfo {
       uint32_t Size;
@@ -89,7 +89,7 @@ class ResourceFileWriter : public Visitor {
       bool IsItalic;
       uint32_t Charset;
     };
-    Optional<FontInfo> Font;
+    std::optional<FontInfo> Font;
     IntOrString Class;
 
     ObjectInfo()
@@ -103,7 +103,7 @@ class ResourceFileWriter : public Visitor {
     using BundleKey = std::pair<uint16_t, uint16_t>;
     // Each bundle is in fact an array of 16 strings.
     struct Bundle {
-      std::array<Optional<std::vector<StringRef>>, 16> Data;
+      std::array<std::optional<std::vector<StringRef>>, 16> Data;
       ObjectInfo DeclTimeInfo;
       uint16_t MemoryFlags;
       Bundle(const ObjectInfo &Info, uint16_t Flags)

diff  --git a/llvm/tools/llvm-rc/ResourceScriptParser.cpp b/llvm/tools/llvm-rc/ResourceScriptParser.cpp
index 7cb4d02e3c58e..c1f00d3e77503 100644
--- a/llvm/tools/llvm-rc/ResourceScriptParser.cpp
+++ b/llvm/tools/llvm-rc/ResourceScriptParser.cpp
@@ -554,7 +554,7 @@ Expected<Control> RCParser::parseControl() {
   RETURN_IF_ERROR(consumeType(Kind::Comma));
 
   IntOrString Class;
-  Optional<IntWithNotMask> Style;
+  std::optional<IntWithNotMask> Style;
   if (ClassUpper == "CONTROL") {
     // CONTROL text, id, class, style, x, y, width, height [, exstyle] [, helpID]
     ASSIGN_OR_RETURN(ClassStr, readString());
@@ -577,12 +577,12 @@ Expected<Control> RCParser::parseControl() {
     }
   }
 
-  Optional<uint32_t> ExStyle;
+  std::optional<uint32_t> ExStyle;
   if (consumeOptionalType(Kind::Comma)) {
     ASSIGN_OR_RETURN(Val, readInt());
     ExStyle = *Val;
   }
-  Optional<uint32_t> HelpID;
+  std::optional<uint32_t> HelpID;
   if (consumeOptionalType(Kind::Comma)) {
     ASSIGN_OR_RETURN(Val, readInt());
     HelpID = *Val;

diff  --git a/llvm/tools/llvm-rc/ResourceScriptStmt.h b/llvm/tools/llvm-rc/ResourceScriptStmt.h
index 4b659f083b40b..71f6a9d212e46 100644
--- a/llvm/tools/llvm-rc/ResourceScriptStmt.h
+++ b/llvm/tools/llvm-rc/ResourceScriptStmt.h
@@ -611,8 +611,8 @@ class Control {
   StringRef Type;
   IntOrString Title;
   uint32_t ID, X, Y, Width, Height;
-  Optional<IntWithNotMask> Style;
-  Optional<uint32_t> ExtStyle, HelpID;
+  std::optional<IntWithNotMask> Style;
+  std::optional<uint32_t> ExtStyle, HelpID;
   IntOrString Class;
 
   // Control classes as described in DLGITEMTEMPLATEEX documentation.
@@ -636,8 +636,9 @@ class Control {
 
   Control(StringRef CtlType, IntOrString CtlTitle, uint32_t CtlID,
           uint32_t PosX, uint32_t PosY, uint32_t ItemWidth, uint32_t ItemHeight,
-          Optional<IntWithNotMask> ItemStyle, Optional<uint32_t> ExtItemStyle,
-          Optional<uint32_t> CtlHelpID, IntOrString CtlClass)
+          std::optional<IntWithNotMask> ItemStyle,
+          std::optional<uint32_t> ExtItemStyle,
+          std::optional<uint32_t> CtlHelpID, IntOrString CtlClass)
       : Type(CtlType), Title(CtlTitle), ID(CtlID), X(PosX), Y(PosY),
         Width(ItemWidth), Height(ItemHeight), Style(ItemStyle),
         ExtStyle(ExtItemStyle), HelpID(CtlHelpID), Class(CtlClass) {}

diff  --git a/llvm/tools/llvm-sim/llvm-sim.cpp b/llvm/tools/llvm-sim/llvm-sim.cpp
index 7b61ad748c9cb..8995705cc7700 100644
--- a/llvm/tools/llvm-sim/llvm-sim.cpp
+++ b/llvm/tools/llvm-sim/llvm-sim.cpp
@@ -41,7 +41,7 @@ static cl::opt<std::string> InputSourceFile(cl::Positional,
 /// \param LLVMInstNum - The mapping of Instructions to their location in the
 /// module represented by an unsigned integer.
 /// \returns The instruction number for \p I if it exists.
-Optional<unsigned>
+std::optional<unsigned>
 getPositionInModule(const Instruction *I,
                     const DenseMap<Instruction *, unsigned> &LLVMInstNum) {
   assert(I && "Instruction is nullptr!");
@@ -80,9 +80,9 @@ exportToFile(const StringRef FilePath,
     // For each file there is a list of the range where the similarity
     // exists.
     for (const IRSimilarityCandidate &C : G) {
-      Optional<unsigned> Start =
+      std::optional<unsigned> Start =
           getPositionInModule((*C.front()).Inst, LLVMInstNum);
-      Optional<unsigned> End =
+      std::optional<unsigned> End =
           getPositionInModule((*C.back()).Inst, LLVMInstNum);
 
       assert(Start &&

diff  --git a/llvm/tools/llvm-xray/xray-account.h b/llvm/tools/llvm-xray/xray-account.h
index 371a9cc708e9a..38d3ec989577f 100644
--- a/llvm/tools/llvm-xray/xray-account.h
+++ b/llvm/tools/llvm-xray/xray-account.h
@@ -45,7 +45,7 @@ class LatencyAccountant {
       RecursionStatus &operator--();
       bool isRecursive() const;
     };
-    Optional<llvm::DenseMap<int32_t, RecursionStatus>> RecursionDepth;
+    std::optional<llvm::DenseMap<int32_t, RecursionStatus>> RecursionDepth;
   };
   typedef llvm::DenseMap<uint32_t, FunctionStack> PerThreadFunctionStackMap;
 


        


More information about the llvm-commits mailing list