[llvm] a81a0c9 - [Remarks] Convert Optional to std::optional

Krzysztof Parzyszek via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 7 06:12:23 PST 2022


Author: Krzysztof Parzyszek
Date: 2022-12-07T08:11:11-06:00
New Revision: a81a0c97f1a0016686fdc5c5d10644fa2628b376

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

LOG: [Remarks] Convert Optional to std::optional

Added: 
    

Modified: 
    llvm/include/llvm/Remarks/BitstreamRemarkParser.h
    llvm/include/llvm/Remarks/BitstreamRemarkSerializer.h
    llvm/include/llvm/Remarks/RemarkLinker.h
    llvm/include/llvm/Remarks/RemarkParser.h
    llvm/include/llvm/Remarks/RemarkStreamer.h
    llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
    llvm/lib/Remarks/BitstreamRemarkParser.cpp
    llvm/lib/Remarks/BitstreamRemarkParser.h
    llvm/lib/Remarks/BitstreamRemarkSerializer.cpp
    llvm/lib/Remarks/RemarkLinker.cpp
    llvm/lib/Remarks/RemarkParser.cpp
    llvm/lib/Remarks/RemarkStreamer.cpp
    llvm/lib/Remarks/YAMLRemarkParser.cpp
    llvm/lib/Remarks/YAMLRemarkParser.h
    llvm/unittests/Remarks/YAMLRemarksParsingTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Remarks/BitstreamRemarkParser.h b/llvm/include/llvm/Remarks/BitstreamRemarkParser.h
index 6df82c59381b4..bfa60332d1a90 100644
--- a/llvm/include/llvm/Remarks/BitstreamRemarkParser.h
+++ b/llvm/include/llvm/Remarks/BitstreamRemarkParser.h
@@ -15,12 +15,12 @@
 #define LLVM_REMARKS_BITSTREAMREMARKPARSER_H
 
 #include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Bitstream/BitstreamReader.h"
 #include "llvm/Support/Error.h"
 #include <array>
 #include <cstdint>
+#include <optional>
 
 namespace llvm {
 namespace remarks {
@@ -33,11 +33,11 @@ struct BitstreamMetaParserHelper {
   BitstreamBlockInfo &BlockInfo;
   /// The parsed content: depending on the container type, some fields might be
   /// empty.
-  Optional<uint64_t> ContainerVersion;
-  Optional<uint8_t> ContainerType;
-  Optional<StringRef> StrTabBuf;
-  Optional<StringRef> ExternalFilePath;
-  Optional<uint64_t> RemarkVersion;
+  std::optional<uint64_t> ContainerVersion;
+  std::optional<uint8_t> ContainerType;
+  std::optional<StringRef> StrTabBuf;
+  std::optional<StringRef> ExternalFilePath;
+  std::optional<uint64_t> RemarkVersion;
 
   /// Continue parsing with \p Stream. \p Stream is expected to contain a
   /// ENTER_SUBBLOCK to the META_BLOCK at the current position.
@@ -55,22 +55,22 @@ struct BitstreamRemarkParserHelper {
   /// The Bitstream reader.
   BitstreamCursor &Stream;
   /// The parsed content: depending on the remark, some fields might be empty.
-  Optional<uint8_t> Type;
-  Optional<uint64_t> RemarkNameIdx;
-  Optional<uint64_t> PassNameIdx;
-  Optional<uint64_t> FunctionNameIdx;
-  Optional<uint64_t> SourceFileNameIdx;
-  Optional<uint32_t> SourceLine;
-  Optional<uint32_t> SourceColumn;
-  Optional<uint64_t> Hotness;
+  std::optional<uint8_t> Type;
+  std::optional<uint64_t> RemarkNameIdx;
+  std::optional<uint64_t> PassNameIdx;
+  std::optional<uint64_t> FunctionNameIdx;
+  std::optional<uint64_t> SourceFileNameIdx;
+  std::optional<uint32_t> SourceLine;
+  std::optional<uint32_t> SourceColumn;
+  std::optional<uint64_t> Hotness;
   struct Argument {
-    Optional<uint64_t> KeyIdx;
-    Optional<uint64_t> ValueIdx;
-    Optional<uint64_t> SourceFileNameIdx;
-    Optional<uint32_t> SourceLine;
-    Optional<uint32_t> SourceColumn;
+    std::optional<uint64_t> KeyIdx;
+    std::optional<uint64_t> ValueIdx;
+    std::optional<uint64_t> SourceFileNameIdx;
+    std::optional<uint32_t> SourceLine;
+    std::optional<uint32_t> SourceColumn;
   };
-  Optional<ArrayRef<Argument>> Args;
+  std::optional<ArrayRef<Argument>> Args;
   /// Avoid re-allocating a vector every time.
   SmallVector<Argument, 8> TmpArgs;
 

diff  --git a/llvm/include/llvm/Remarks/BitstreamRemarkSerializer.h b/llvm/include/llvm/Remarks/BitstreamRemarkSerializer.h
index f3c2c0dbb9d3a..6236800337508 100644
--- a/llvm/include/llvm/Remarks/BitstreamRemarkSerializer.h
+++ b/llvm/include/llvm/Remarks/BitstreamRemarkSerializer.h
@@ -106,8 +106,8 @@ struct BitstreamRemarkSerializerHelper {
 
   /// Emit the metadata for the remarks.
   void emitMetaBlock(uint64_t ContainerVersion,
-                     Optional<uint64_t> RemarkVersion,
-                     Optional<const StringTable *> StrTab = std::nullopt,
+                     std::optional<uint64_t> RemarkVersion,
+                     std::optional<const StringTable *> StrTab = std::nullopt,
                      std::optional<StringRef> Filename = std::nullopt);
 
   /// Emit a remark block. The string table is required.
@@ -162,19 +162,19 @@ struct BitstreamMetaSerializer : public MetaSerializer {
   /// BitstreamRemarkSerializerHelper, or with [2] one that is owned by the meta
   /// serializer. In case of [1], we need to be able to store a reference to the
   /// object, while in case of [2] we need to store the whole object.
-  Optional<BitstreamRemarkSerializerHelper> TmpHelper;
+  std::optional<BitstreamRemarkSerializerHelper> TmpHelper;
   /// The actual helper, that can point to \p TmpHelper or to an external helper
   /// object.
   BitstreamRemarkSerializerHelper *Helper = nullptr;
 
-  Optional<const StringTable *> StrTab;
+  std::optional<const StringTable *> StrTab;
   std::optional<StringRef> ExternalFilename;
 
   /// Create a new meta serializer based on \p ContainerType.
-  BitstreamMetaSerializer(raw_ostream &OS,
-                          BitstreamRemarkContainerType ContainerType,
-                          Optional<const StringTable *> StrTab = std::nullopt,
-                          std::optional<StringRef> ExternalFilename = std::nullopt)
+  BitstreamMetaSerializer(
+      raw_ostream &OS, BitstreamRemarkContainerType ContainerType,
+      std::optional<const StringTable *> StrTab = std::nullopt,
+      std::optional<StringRef> ExternalFilename = std::nullopt)
       : MetaSerializer(OS), TmpHelper(std::nullopt), Helper(nullptr),
         StrTab(StrTab), ExternalFilename(ExternalFilename) {
     TmpHelper.emplace(ContainerType);
@@ -182,10 +182,10 @@ struct BitstreamMetaSerializer : public MetaSerializer {
   }
 
   /// Create a new meta serializer based on a previously built \p Helper.
-  BitstreamMetaSerializer(raw_ostream &OS,
-                          BitstreamRemarkSerializerHelper &Helper,
-                          Optional<const StringTable *> StrTab = std::nullopt,
-                          std::optional<StringRef> ExternalFilename = std::nullopt)
+  BitstreamMetaSerializer(
+      raw_ostream &OS, BitstreamRemarkSerializerHelper &Helper,
+      std::optional<const StringTable *> StrTab = std::nullopt,
+      std::optional<StringRef> ExternalFilename = std::nullopt)
       : MetaSerializer(OS), TmpHelper(std::nullopt), Helper(&Helper),
         StrTab(StrTab), ExternalFilename(ExternalFilename) {}
 

diff  --git a/llvm/include/llvm/Remarks/RemarkLinker.h b/llvm/include/llvm/Remarks/RemarkLinker.h
index f5d8d9ba3f5b1..307eb3f6e84a2 100644
--- a/llvm/include/llvm/Remarks/RemarkLinker.h
+++ b/llvm/include/llvm/Remarks/RemarkLinker.h
@@ -18,6 +18,7 @@
 #include "llvm/Remarks/RemarkStringTable.h"
 #include "llvm/Support/Error.h"
 #include <memory>
+#include <optional>
 #include <set>
 
 namespace llvm {
@@ -51,7 +52,7 @@ struct RemarkLinker {
   std::set<std::unique_ptr<Remark>, RemarkPtrCompare> Remarks;
 
   /// A path to append before the external file path found in remark metadata.
-  Optional<std::string> PrependPath;
+  std::optional<std::string> PrependPath;
 
   /// Keep this remark. If it's already in the set, discard it.
   Remark &keep(std::unique_ptr<Remark> Remark);
@@ -65,12 +66,13 @@ struct RemarkLinker {
   /// \p Buffer.
   /// \p Buffer can be either a standalone remark container or just
   /// metadata. This takes care of uniquing and merging the remarks.
-  Error link(StringRef Buffer, Optional<Format> RemarkFormat = std::nullopt);
+  Error link(StringRef Buffer,
+             std::optional<Format> RemarkFormat = std::nullopt);
 
   /// Link the remarks found in \p Obj by looking for the right section and
   /// calling the method above.
   Error link(const object::ObjectFile &Obj,
-             Optional<Format> RemarkFormat = std::nullopt);
+             std::optional<Format> RemarkFormat = std::nullopt);
 
   /// Serialize the linked remarks to the stream \p OS, using the format \p
   /// RemarkFormat.
@@ -94,7 +96,7 @@ struct RemarkLinker {
 /// Returns a buffer with the contents of the remarks section depending on the
 /// format of the file. If the section doesn't exist, this returns an empty
 /// optional.
-Expected<Optional<StringRef>>
+Expected<std::optional<StringRef>>
 getRemarksSectionContents(const object::ObjectFile &Obj);
 
 } // end namespace remarks

diff  --git a/llvm/include/llvm/Remarks/RemarkParser.h b/llvm/include/llvm/Remarks/RemarkParser.h
index f131857e1fc91..1333c582eba4f 100644
--- a/llvm/include/llvm/Remarks/RemarkParser.h
+++ b/llvm/include/llvm/Remarks/RemarkParser.h
@@ -17,6 +17,7 @@
 #include "llvm/Remarks/RemarkFormat.h"
 #include "llvm/Support/Error.h"
 #include <memory>
+#include <optional>
 
 namespace llvm {
 namespace remarks {
@@ -84,8 +85,8 @@ createRemarkParser(Format ParserFormat, StringRef Buf,
 
 Expected<std::unique_ptr<RemarkParser>> createRemarkParserFromMeta(
     Format ParserFormat, StringRef Buf,
-    Optional<ParsedStringTable> StrTab = std::nullopt,
-    Optional<StringRef> ExternalFilePrependPath = std::nullopt);
+    std::optional<ParsedStringTable> StrTab = std::nullopt,
+    std::optional<StringRef> ExternalFilePrependPath = std::nullopt);
 
 } // end namespace remarks
 } // end namespace llvm

diff  --git a/llvm/include/llvm/Remarks/RemarkStreamer.h b/llvm/include/llvm/Remarks/RemarkStreamer.h
index c86394fcbeb0c..5b1cc81cdbf50 100644
--- a/llvm/include/llvm/Remarks/RemarkStreamer.h
+++ b/llvm/include/llvm/Remarks/RemarkStreamer.h
@@ -30,11 +30,11 @@
 #ifndef LLVM_REMARKS_REMARKSTREAMER_H
 #define LLVM_REMARKS_REMARKSTREAMER_H
 
-#include "llvm/ADT/Optional.h"
 #include "llvm/Remarks/RemarkSerializer.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/Regex.h"
 #include <memory>
+#include <optional>
 
 namespace llvm {
 
@@ -43,19 +43,19 @@ class raw_ostream;
 namespace remarks {
 class RemarkStreamer final {
   /// The regex used to filter remarks based on the passes that emit them.
-  Optional<Regex> PassFilter;
+  std::optional<Regex> PassFilter;
   /// The object used to serialize the remarks to a specific format.
   std::unique_ptr<remarks::RemarkSerializer> RemarkSerializer;
   /// The filename that the remark diagnostics are emitted to.
-  const Optional<std::string> Filename;
+  const std::optional<std::string> Filename;
 
 public:
   RemarkStreamer(std::unique_ptr<remarks::RemarkSerializer> RemarkSerializer,
-                 Optional<StringRef> Filename = std::nullopt);
+                 std::optional<StringRef> Filename = std::nullopt);
 
   /// Return the filename that the remark diagnostics are emitted to.
-  Optional<StringRef> getFilename() const {
-    return Filename ? Optional<StringRef>(*Filename) : std::nullopt;
+  std::optional<StringRef> getFilename() const {
+    return Filename ? std::optional<StringRef>(*Filename) : std::nullopt;
   }
   /// Return stream that the remark diagnostics are emitted to.
   raw_ostream &getStream() { return RemarkSerializer->OS; }

diff  --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 11eff4dd20096..f87e2cd38f750 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -2059,7 +2059,7 @@ void AsmPrinter::emitRemarksSection(remarks::RemarkStreamer &RS) {
   remarks::RemarkSerializer &RemarkSerializer = RS.getSerializer();
 
   std::optional<SmallString<128>> Filename;
-  if (Optional<StringRef> FilenameRef = RS.getFilename()) {
+  if (std::optional<StringRef> FilenameRef = RS.getFilename()) {
     Filename = *FilenameRef;
     sys::fs::make_absolute(*Filename);
     assert(!Filename->empty() && "The filename can't be empty.");

diff  --git a/llvm/lib/Remarks/BitstreamRemarkParser.cpp b/llvm/lib/Remarks/BitstreamRemarkParser.cpp
index 08b8386a30efb..85fe814f1fda8 100644
--- a/llvm/lib/Remarks/BitstreamRemarkParser.cpp
+++ b/llvm/lib/Remarks/BitstreamRemarkParser.cpp
@@ -307,8 +307,8 @@ static Error advanceToMetaBlock(BitstreamParserHelper &Helper) {
 
 Expected<std::unique_ptr<BitstreamRemarkParser>>
 remarks::createBitstreamParserFromMeta(
-    StringRef Buf, Optional<ParsedStringTable> StrTab,
-    Optional<StringRef> ExternalFilePrependPath) {
+    StringRef Buf, std::optional<ParsedStringTable> StrTab,
+    std::optional<StringRef> ExternalFilePrependPath) {
   BitstreamParserHelper Helper(Buf);
   Expected<std::array<char, 4>> MagicNumber = Helper.parseMagic();
   if (!MagicNumber)
@@ -367,14 +367,14 @@ Error BitstreamRemarkParser::parseMeta() {
 
 Error BitstreamRemarkParser::processCommonMeta(
     BitstreamMetaParserHelper &Helper) {
-  if (Optional<uint64_t> Version = Helper.ContainerVersion)
+  if (std::optional<uint64_t> Version = Helper.ContainerVersion)
     ContainerVersion = *Version;
   else
     return createStringError(
         std::make_error_code(std::errc::illegal_byte_sequence),
         "Error while parsing BLOCK_META: missing container version.");
 
-  if (Optional<uint8_t> Type = Helper.ContainerType) {
+  if (std::optional<uint8_t> Type = Helper.ContainerType) {
     // Always >= BitstreamRemarkContainerType::First since it's unsigned.
     if (*Type > static_cast<uint8_t>(BitstreamRemarkContainerType::Last))
       return createStringError(
@@ -391,7 +391,7 @@ Error BitstreamRemarkParser::processCommonMeta(
 }
 
 static Error processStrTab(BitstreamRemarkParser &P,
-                           Optional<StringRef> StrTabBuf) {
+                           std::optional<StringRef> StrTabBuf) {
   if (!StrTabBuf)
     return createStringError(
         std::make_error_code(std::errc::illegal_byte_sequence),
@@ -402,7 +402,7 @@ static Error processStrTab(BitstreamRemarkParser &P,
 }
 
 static Error processRemarkVersion(BitstreamRemarkParser &P,
-                                  Optional<uint64_t> RemarkVersion) {
+                                  std::optional<uint64_t> RemarkVersion) {
   if (!RemarkVersion)
     return createStringError(
         std::make_error_code(std::errc::illegal_byte_sequence),
@@ -412,7 +412,7 @@ static Error processRemarkVersion(BitstreamRemarkParser &P,
 }
 
 Error BitstreamRemarkParser::processExternalFilePath(
-    Optional<StringRef> ExternalFilePath) {
+    std::optional<StringRef> ExternalFilePath) {
   if (!ExternalFilePath)
     return createStringError(
         std::make_error_code(std::errc::illegal_byte_sequence),

diff  --git a/llvm/lib/Remarks/BitstreamRemarkParser.h b/llvm/lib/Remarks/BitstreamRemarkParser.h
index 78f18a68c1ec4..fc786fc57622d 100644
--- a/llvm/lib/Remarks/BitstreamRemarkParser.h
+++ b/llvm/lib/Remarks/BitstreamRemarkParser.h
@@ -13,13 +13,13 @@
 #ifndef LLVM_LIB_REMARKS_BITSTREAM_REMARK_PARSER_H
 #define LLVM_LIB_REMARKS_BITSTREAM_REMARK_PARSER_H
 
-#include "llvm/ADT/Optional.h"
 #include "llvm/Remarks/BitstreamRemarkContainer.h"
 #include "llvm/Remarks/BitstreamRemarkParser.h"
 #include "llvm/Remarks/RemarkFormat.h"
 #include "llvm/Remarks/RemarkParser.h"
 #include <cstdint>
 #include <memory>
+#include <optional>
 
 namespace llvm {
 namespace remarks {
@@ -31,7 +31,7 @@ struct BitstreamRemarkParser : public RemarkParser {
   /// The buffer to parse.
   BitstreamParserHelper ParserHelper;
   /// The string table used for parsing strings.
-  Optional<ParsedStringTable> StrTab;
+  std::optional<ParsedStringTable> StrTab;
   /// Temporary remark buffer used when the remarks are stored separately.
   std::unique_ptr<MemoryBuffer> TmpRemarkBuffer;
   /// The common metadata used to decide how to parse the buffer.
@@ -73,12 +73,12 @@ struct BitstreamRemarkParser : public RemarkParser {
   Error processSeparateRemarksMetaMeta(BitstreamMetaParserHelper &Helper);
   Expected<std::unique_ptr<Remark>>
   processRemark(BitstreamRemarkParserHelper &Helper);
-  Error processExternalFilePath(Optional<StringRef> ExternalFilePath);
+  Error processExternalFilePath(std::optional<StringRef> ExternalFilePath);
 };
 
 Expected<std::unique_ptr<BitstreamRemarkParser>> createBitstreamParserFromMeta(
-    StringRef Buf, Optional<ParsedStringTable> StrTab = std::nullopt,
-    Optional<StringRef> ExternalFilePrependPath = std::nullopt);
+    StringRef Buf, std::optional<ParsedStringTable> StrTab = std::nullopt,
+    std::optional<StringRef> ExternalFilePrependPath = std::nullopt);
 
 } // end namespace remarks
 } // end namespace llvm

diff  --git a/llvm/lib/Remarks/BitstreamRemarkSerializer.cpp b/llvm/lib/Remarks/BitstreamRemarkSerializer.cpp
index 542896765d824..b2627196bce62 100644
--- a/llvm/lib/Remarks/BitstreamRemarkSerializer.cpp
+++ b/llvm/lib/Remarks/BitstreamRemarkSerializer.cpp
@@ -232,8 +232,9 @@ void BitstreamRemarkSerializerHelper::setupBlockInfo() {
 }
 
 void BitstreamRemarkSerializerHelper::emitMetaBlock(
-    uint64_t ContainerVersion, Optional<uint64_t> RemarkVersion,
-    Optional<const StringTable *> StrTab, std::optional<StringRef> Filename) {
+    uint64_t ContainerVersion, std::optional<uint64_t> RemarkVersion,
+    std::optional<const StringTable *> StrTab,
+    std::optional<StringRef> Filename) {
   // Emit the meta block
   Bitstream.EnterSubblock(META_BLOCK_ID, 3);
 
@@ -354,7 +355,8 @@ void BitstreamRemarkSerializer::emit(const Remark &Remark) {
         Helper.ContainerType == BitstreamRemarkContainerType::Standalone;
     BitstreamMetaSerializer MetaSerializer(
         OS, Helper,
-        IsStandalone ? &*StrTab : Optional<const StringTable *>(std::nullopt));
+        IsStandalone ? &*StrTab
+                     : std::optional<const StringTable *>(std::nullopt));
     MetaSerializer.emit();
     DidSetUp = true;
   }

diff  --git a/llvm/lib/Remarks/RemarkLinker.cpp b/llvm/lib/Remarks/RemarkLinker.cpp
index d21bcb1569d1c..74acb0835ff83 100644
--- a/llvm/lib/Remarks/RemarkLinker.cpp
+++ b/llvm/lib/Remarks/RemarkLinker.cpp
@@ -17,6 +17,7 @@
 #include "llvm/Remarks/RemarkParser.h"
 #include "llvm/Remarks/RemarkSerializer.h"
 #include "llvm/Support/Error.h"
+#include <optional>
 
 using namespace llvm;
 using namespace llvm::remarks;
@@ -34,7 +35,7 @@ getRemarksSectionName(const object::ObjectFile &Obj) {
                            "Unsupported file format.");
 }
 
-Expected<Optional<StringRef>>
+Expected<std::optional<StringRef>>
 llvm::remarks::getRemarksSectionContents(const object::ObjectFile &Obj) {
   Expected<StringRef> SectionName = getRemarksSectionName(Obj);
   if (!SectionName)
@@ -52,7 +53,7 @@ llvm::remarks::getRemarksSectionContents(const object::ObjectFile &Obj) {
     else
       return Contents.takeError();
   }
-  return Optional<StringRef>{};
+  return std::optional<StringRef>{};
 }
 
 Remark &RemarkLinker::keep(std::unique_ptr<Remark> Remark) {
@@ -68,7 +69,7 @@ void RemarkLinker::setExternalFilePrependPath(StringRef PrependPathIn) {
 // Discard remarks with no source location.
 static bool shouldKeepRemark(const Remark &R) { return R.Loc.has_value(); }
 
-Error RemarkLinker::link(StringRef Buffer, Optional<Format> RemarkFormat) {
+Error RemarkLinker::link(StringRef Buffer, std::optional<Format> RemarkFormat) {
   if (!RemarkFormat) {
     Expected<Format> ParserFormat = magicToFormat(Buffer);
     if (!ParserFormat)
@@ -79,8 +80,8 @@ Error RemarkLinker::link(StringRef Buffer, Optional<Format> RemarkFormat) {
   Expected<std::unique_ptr<RemarkParser>> MaybeParser =
       createRemarkParserFromMeta(
           *RemarkFormat, Buffer, /*StrTab=*/std::nullopt,
-          PrependPath ? Optional<StringRef>(StringRef(*PrependPath))
-                      : Optional<StringRef>());
+          PrependPath ? std::optional<StringRef>(StringRef(*PrependPath))
+                      : std::optional<StringRef>());
   if (!MaybeParser)
     return MaybeParser.takeError();
 
@@ -105,12 +106,13 @@ Error RemarkLinker::link(StringRef Buffer, Optional<Format> RemarkFormat) {
 }
 
 Error RemarkLinker::link(const object::ObjectFile &Obj,
-                         Optional<Format> RemarkFormat) {
-  Expected<Optional<StringRef>> SectionOrErr = getRemarksSectionContents(Obj);
+                         std::optional<Format> RemarkFormat) {
+  Expected<std::optional<StringRef>> SectionOrErr =
+      getRemarksSectionContents(Obj);
   if (!SectionOrErr)
     return SectionOrErr.takeError();
 
-  if (Optional<StringRef> Section = *SectionOrErr)
+  if (std::optional<StringRef> Section = *SectionOrErr)
     return link(*Section, RemarkFormat);
   return Error::success();
 }

diff  --git a/llvm/lib/Remarks/RemarkParser.cpp b/llvm/lib/Remarks/RemarkParser.cpp
index 67ec0b092825e..7fccb94014b9a 100644
--- a/llvm/lib/Remarks/RemarkParser.cpp
+++ b/llvm/lib/Remarks/RemarkParser.cpp
@@ -87,8 +87,8 @@ llvm::remarks::createRemarkParser(Format ParserFormat, StringRef Buf,
 
 Expected<std::unique_ptr<RemarkParser>>
 llvm::remarks::createRemarkParserFromMeta(
-    Format ParserFormat, StringRef Buf, Optional<ParsedStringTable> StrTab,
-    Optional<StringRef> ExternalFilePrependPath) {
+    Format ParserFormat, StringRef Buf, std::optional<ParsedStringTable> StrTab,
+    std::optional<StringRef> ExternalFilePrependPath) {
   switch (ParserFormat) {
   // Depending on the metadata, the format can be either yaml or yaml-strtab,
   // regardless of the input argument.

diff  --git a/llvm/lib/Remarks/RemarkStreamer.cpp b/llvm/lib/Remarks/RemarkStreamer.cpp
index 8ad2ce6948a40..9f4676ce37ab9 100644
--- a/llvm/lib/Remarks/RemarkStreamer.cpp
+++ b/llvm/lib/Remarks/RemarkStreamer.cpp
@@ -12,6 +12,7 @@
 
 #include "llvm/Remarks/RemarkStreamer.h"
 #include "llvm/Support/CommandLine.h"
+#include <optional>
 
 using namespace llvm;
 using namespace llvm::remarks;
@@ -25,9 +26,9 @@ static cl::opt<cl::boolOrDefault> EnableRemarksSection(
 
 RemarkStreamer::RemarkStreamer(
     std::unique_ptr<remarks::RemarkSerializer> RemarkSerializer,
-    Optional<StringRef> FilenameIn)
+    std::optional<StringRef> FilenameIn)
     : RemarkSerializer(std::move(RemarkSerializer)),
-      Filename(FilenameIn ? Optional<std::string>(FilenameIn->str())
+      Filename(FilenameIn ? std::optional<std::string>(FilenameIn->str())
                           : std::nullopt) {}
 
 Error RemarkStreamer::setFilter(StringRef Filter) {

diff  --git a/llvm/lib/Remarks/YAMLRemarkParser.cpp b/llvm/lib/Remarks/YAMLRemarkParser.cpp
index 265371c0839aa..4996ab6b08b98 100644
--- a/llvm/lib/Remarks/YAMLRemarkParser.cpp
+++ b/llvm/lib/Remarks/YAMLRemarkParser.cpp
@@ -108,10 +108,9 @@ static Expected<ParsedStringTable> parseStrTab(StringRef &Buf,
   return Expected<ParsedStringTable>(std::move(Result));
 }
 
-Expected<std::unique_ptr<YAMLRemarkParser>>
-remarks::createYAMLParserFromMeta(StringRef Buf,
-                                  Optional<ParsedStringTable> StrTab,
-                                  Optional<StringRef> ExternalFilePrependPath) {
+Expected<std::unique_ptr<YAMLRemarkParser>> remarks::createYAMLParserFromMeta(
+    StringRef Buf, std::optional<ParsedStringTable> StrTab,
+    std::optional<StringRef> ExternalFilePrependPath) {
   // We now have a magic number. The metadata has to be correct.
   Expected<bool> isMeta = parseMagic(Buf);
   if (!isMeta)
@@ -171,7 +170,7 @@ YAMLRemarkParser::YAMLRemarkParser(StringRef Buf)
     : YAMLRemarkParser(Buf, std::nullopt) {}
 
 YAMLRemarkParser::YAMLRemarkParser(StringRef Buf,
-                                   Optional<ParsedStringTable> StrTab)
+                                   std::optional<ParsedStringTable> StrTab)
     : RemarkParser{Format::YAML}, StrTab(std::move(StrTab)),
       SM(setupSM(LastErrorMessage)), Stream(Buf, SM), YAMLIt(Stream.begin()) {}
 

diff  --git a/llvm/lib/Remarks/YAMLRemarkParser.h b/llvm/lib/Remarks/YAMLRemarkParser.h
index 44425e85f1a9d..8ef72e16be74e 100644
--- a/llvm/lib/Remarks/YAMLRemarkParser.h
+++ b/llvm/lib/Remarks/YAMLRemarkParser.h
@@ -13,7 +13,6 @@
 #ifndef LLVM_REMARKS_YAML_REMARK_PARSER_H
 #define LLVM_REMARKS_YAML_REMARK_PARSER_H
 
-#include "llvm/ADT/Optional.h"
 #include "llvm/Remarks/Remark.h"
 #include "llvm/Remarks/RemarkParser.h"
 #include "llvm/Support/Error.h"
@@ -21,6 +20,7 @@
 #include "llvm/Support/SourceMgr.h"
 #include "llvm/Support/YAMLParser.h"
 #include "llvm/Support/raw_ostream.h"
+#include <optional>
 #include <string>
 
 namespace llvm {
@@ -47,7 +47,7 @@ class YAMLParseError : public ErrorInfo<YAMLParseError> {
 /// Regular YAML to Remark parser.
 struct YAMLRemarkParser : public RemarkParser {
   /// The string table used for parsing strings.
-  Optional<ParsedStringTable> StrTab;
+  std::optional<ParsedStringTable> StrTab;
   /// Last error message that can come from the YAML parser diagnostics.
   /// We need this for catching errors in the constructor.
   std::string LastErrorMessage;
@@ -70,7 +70,7 @@ struct YAMLRemarkParser : public RemarkParser {
   }
 
 protected:
-  YAMLRemarkParser(StringRef Buf, Optional<ParsedStringTable> StrTab);
+  YAMLRemarkParser(StringRef Buf, std::optional<ParsedStringTable> StrTab);
   /// Create a YAMLParseError error from an existing error generated by the YAML
   /// parser.
   /// If there is no error, this returns Success.
@@ -108,8 +108,8 @@ struct YAMLStrTabRemarkParser : public YAMLRemarkParser {
 };
 
 Expected<std::unique_ptr<YAMLRemarkParser>> createYAMLParserFromMeta(
-    StringRef Buf, Optional<ParsedStringTable> StrTab = std::nullopt,
-    Optional<StringRef> ExternalFilePrependPath = std::nullopt);
+    StringRef Buf, std::optional<ParsedStringTable> StrTab = std::nullopt,
+    std::optional<StringRef> ExternalFilePrependPath = std::nullopt);
 
 } // end namespace remarks
 } // end namespace llvm

diff  --git a/llvm/unittests/Remarks/YAMLRemarksParsingTest.cpp b/llvm/unittests/Remarks/YAMLRemarksParsingTest.cpp
index 2741a79a2c8e7..85b6fb435528a 100644
--- a/llvm/unittests/Remarks/YAMLRemarksParsingTest.cpp
+++ b/llvm/unittests/Remarks/YAMLRemarksParsingTest.cpp
@@ -10,6 +10,7 @@
 #include "llvm/Remarks/Remark.h"
 #include "llvm/Remarks/RemarkParser.h"
 #include "gtest/gtest.h"
+#include <optional>
 
 using namespace llvm;
 
@@ -70,7 +71,7 @@ enum class CmpType {
 
 void parseExpectErrorMeta(
     StringRef Buf, const char *Error, CmpType Cmp,
-    Optional<StringRef> ExternalFilePrependPath = std::nullopt) {
+    std::optional<StringRef> ExternalFilePrependPath = std::nullopt) {
   std::string ErrorStr;
   raw_string_ostream Stream(ErrorStr);
 


        


More information about the llvm-commits mailing list