#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 {
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.
/// 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;
/// 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.
/// 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);
}
/// 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) {}
#include "llvm/Remarks/RemarkStringTable.h"
#include "llvm/Support/Error.h"
#include <memory>
+#include <optional>
#include <set>
namespace llvm {
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);
/// \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.
/// 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
#include "llvm/Remarks/RemarkFormat.h"
#include "llvm/Support/Error.h"
#include <memory>
+#include <optional>
namespace llvm {
namespace remarks {
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
#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 {
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; }
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.");
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)
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(
}
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),
}
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),
}
Error BitstreamRemarkParser::processExternalFilePath(
- Optional<StringRef> ExternalFilePath) {
+ std::optional<StringRef> ExternalFilePath) {
if (!ExternalFilePath)
return createStringError(
std::make_error_code(std::errc::illegal_byte_sequence),
#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 {
/// 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.
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
}
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);
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;
}
#include "llvm/Remarks/RemarkParser.h"
#include "llvm/Remarks/RemarkSerializer.h"
#include "llvm/Support/Error.h"
+#include <optional>
using namespace llvm;
using namespace llvm::remarks;
"Unsupported file format.");
}
-Expected<Optional<StringRef>>
+Expected<std::optional<StringRef>>
llvm::remarks::getRemarksSectionContents(const object::ObjectFile &Obj) {
Expected<StringRef> SectionName = getRemarksSectionName(Obj);
if (!SectionName)
else
return Contents.takeError();
}
- return Optional<StringRef>{};
+ return std::optional<StringRef>{};
}
Remark &RemarkLinker::keep(std::unique_ptr<Remark> Remark) {
// 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)
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();
}
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();
}
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.
#include "llvm/Remarks/RemarkStreamer.h"
#include "llvm/Support/CommandLine.h"
+#include <optional>
using namespace llvm;
using namespace llvm::remarks;
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) {
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)
: 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()) {}
#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"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/YAMLParser.h"
#include "llvm/Support/raw_ostream.h"
+#include <optional>
#include <string>
namespace llvm {
/// 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;
}
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.
};
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
#include "llvm/Remarks/Remark.h"
#include "llvm/Remarks/RemarkParser.h"
#include "gtest/gtest.h"
+#include <optional>
using namespace llvm;
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);