summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/include/llvm/IR/RemarkStreamer.h4
-rw-r--r--llvm/include/llvm/Remarks/Remark.h1
-rw-r--r--llvm/include/llvm/Remarks/RemarkFormat.h33
-rw-r--r--llvm/include/llvm/Remarks/RemarkParser.h7
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp1
-rw-r--r--llvm/lib/IR/RemarkStreamer.cpp22
-rw-r--r--llvm/lib/Remarks/CMakeLists.txt1
-rw-r--r--llvm/lib/Remarks/RemarkFormat.cpp30
-rw-r--r--llvm/lib/Remarks/RemarkParser.cpp33
-rw-r--r--llvm/lib/Remarks/RemarkParserImpl.h4
-rw-r--r--llvm/lib/Remarks/YAMLRemarkParser.h4
-rw-r--r--llvm/tools/llvm-opt-report/OptReport.cpp2
-rw-r--r--llvm/unittests/Remarks/YAMLRemarksParsingTest.cpp10
13 files changed, 100 insertions, 52 deletions
diff --git a/llvm/include/llvm/IR/RemarkStreamer.h b/llvm/include/llvm/IR/RemarkStreamer.h
index 9b6d82ee30c..c84de9aea35 100644
--- a/llvm/include/llvm/IR/RemarkStreamer.h
+++ b/llvm/include/llvm/IR/RemarkStreamer.h
@@ -90,10 +90,6 @@ struct RemarkSetupFormatError : RemarkSetupErrorInfo<RemarkSetupFormatError> {
using RemarkSetupErrorInfo<RemarkSetupFormatError>::RemarkSetupErrorInfo;
};
-enum class RemarksSerializerFormat { Unknown, YAML };
-
-Expected<RemarksSerializerFormat> parseSerializerFormat(StringRef Format);
-
/// Setup optimization remarks.
Expected<std::unique_ptr<ToolOutputFile>>
setupOptimizationRemarks(LLVMContext &Context, StringRef RemarksFilename,
diff --git a/llvm/include/llvm/Remarks/Remark.h b/llvm/include/llvm/Remarks/Remark.h
index d916728e0b9..4241fb1fda3 100644
--- a/llvm/include/llvm/Remarks/Remark.h
+++ b/llvm/include/llvm/Remarks/Remark.h
@@ -24,7 +24,6 @@ namespace llvm {
namespace remarks {
constexpr uint64_t Version = 0;
-constexpr StringRef Magic("REMARKS", 7);
/// The debug location used to track a remark back to the source file.
struct RemarkLocation {
diff --git a/llvm/include/llvm/Remarks/RemarkFormat.h b/llvm/include/llvm/Remarks/RemarkFormat.h
new file mode 100644
index 00000000000..e167d99d251
--- /dev/null
+++ b/llvm/include/llvm/Remarks/RemarkFormat.h
@@ -0,0 +1,33 @@
+//===-- llvm/Remarks/RemarkFormat.h - The format of remarks -----*- C++/-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file defines utilities to deal with the format of remarks.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_REMARKS_REMARK_FORMAT_H
+#define LLVM_REMARKS_REMARK_FORMAT_H
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Error.h"
+
+namespace llvm {
+namespace remarks {
+
+constexpr StringRef Magic("REMARKS", 7);
+
+/// The format used for serializing/deserializing remarks.
+enum class Format { Unknown, YAML };
+
+/// Parse and validate a string for the remark format.
+Expected<Format> parseFormat(StringRef FormatStr);
+
+} // end namespace remarks
+} // end namespace llvm
+
+#endif /* LLVM_REMARKS_REMARK_FORMAT_H */
diff --git a/llvm/include/llvm/Remarks/RemarkParser.h b/llvm/include/llvm/Remarks/RemarkParser.h
index 457b2fbaa5f..b956f0c4025 100644
--- a/llvm/include/llvm/Remarks/RemarkParser.h
+++ b/llvm/include/llvm/Remarks/RemarkParser.h
@@ -16,6 +16,7 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Remarks/Remark.h"
+#include "llvm/Remarks/RemarkFormat.h"
#include "llvm/Support/Error.h"
#include <memory>
@@ -25,8 +26,6 @@ namespace remarks {
struct ParserImpl;
struct ParsedStringTable;
-enum class ParserFormat { YAML };
-
/// Parser used to parse a raw buffer to remarks::Remark objects.
struct Parser {
/// The hidden implementation of the parser.
@@ -35,11 +34,11 @@ struct Parser {
/// Create a parser parsing \p Buffer to Remark objects.
/// This constructor should be only used for parsing remarks without a string
/// table.
- Parser(ParserFormat Format, StringRef Buffer);
+ Parser(Format ParserFormat, StringRef Buffer);
/// Create a parser parsing \p Buffer to Remark objects, using \p StrTab as a
/// string table.
- Parser(ParserFormat Format, StringRef Buffer,
+ Parser(Format ParserFormat, StringRef Buffer,
const ParsedStringTable &StrTab);
// Needed because ParserImpl is an incomplete type.
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 174a9bcfd9b..54f6cc2d557 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -100,6 +100,7 @@
#include "llvm/MC/SectionKind.h"
#include "llvm/Pass.h"
#include "llvm/Remarks/Remark.h"
+#include "llvm/Remarks/RemarkFormat.h"
#include "llvm/Remarks/RemarkStringTable.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/CommandLine.h"
diff --git a/llvm/lib/IR/RemarkStreamer.cpp b/llvm/lib/IR/RemarkStreamer.cpp
index 2c3bc8406e5..32adef181f4 100644
--- a/llvm/lib/IR/RemarkStreamer.cpp
+++ b/llvm/lib/IR/RemarkStreamer.cpp
@@ -15,6 +15,7 @@
#include "llvm/IR/DiagnosticInfo.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GlobalValue.h"
+#include "llvm/Remarks/RemarkFormat.h"
using namespace llvm;
@@ -112,30 +113,16 @@ char RemarkSetupPatternError::ID = 0;
char RemarkSetupFormatError::ID = 0;
static std::unique_ptr<remarks::Serializer>
-formatToSerializer(RemarksSerializerFormat RemarksFormat, raw_ostream &OS) {
+formatToSerializer(remarks::Format RemarksFormat, raw_ostream &OS) {
switch (RemarksFormat) {
default:
llvm_unreachable("Unknown remark serializer format.");
return nullptr;
- case RemarksSerializerFormat::YAML:
+ case remarks::Format::YAML:
return llvm::make_unique<remarks::YAMLSerializer>(OS);
};
}
-Expected<RemarksSerializerFormat>
-llvm::parseSerializerFormat(StringRef StrFormat) {
- auto Format = StringSwitch<RemarksSerializerFormat>(StrFormat)
- .Cases("", "yaml", RemarksSerializerFormat::YAML)
- .Default(RemarksSerializerFormat::Unknown);
-
- if (Format == RemarksSerializerFormat::Unknown)
- return createStringError(std::make_error_code(std::errc::invalid_argument),
- "Unknown remark serializer format: '%s'",
- StrFormat.data());
-
- return Format;
-}
-
Expected<std::unique_ptr<ToolOutputFile>>
llvm::setupOptimizationRemarks(LLVMContext &Context, StringRef RemarksFilename,
StringRef RemarksPasses, StringRef RemarksFormat,
@@ -158,8 +145,7 @@ llvm::setupOptimizationRemarks(LLVMContext &Context, StringRef RemarksFilename,
if (EC)
return make_error<RemarkSetupFileError>(errorCodeToError(EC));
- Expected<RemarksSerializerFormat> Format =
- parseSerializerFormat(RemarksFormat);
+ Expected<remarks::Format> Format = remarks::parseFormat(RemarksFormat);
if (Error E = Format.takeError())
return make_error<RemarkSetupFormatError>(std::move(E));
diff --git a/llvm/lib/Remarks/CMakeLists.txt b/llvm/lib/Remarks/CMakeLists.txt
index 73383597acc..06ddbab6de5 100644
--- a/llvm/lib/Remarks/CMakeLists.txt
+++ b/llvm/lib/Remarks/CMakeLists.txt
@@ -1,5 +1,6 @@
add_llvm_library(LLVMRemarks
Remark.cpp
+ RemarkFormat.cpp
RemarkParser.cpp
RemarkStringTable.cpp
YAMLRemarkParser.cpp
diff --git a/llvm/lib/Remarks/RemarkFormat.cpp b/llvm/lib/Remarks/RemarkFormat.cpp
new file mode 100644
index 00000000000..bcd0f753ff6
--- /dev/null
+++ b/llvm/lib/Remarks/RemarkFormat.cpp
@@ -0,0 +1,30 @@
+//===- RemarkFormat.cpp --------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// Implementation of utilities to handle the different remark formats.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Remarks/RemarkFormat.h"
+#include "llvm/ADT/StringSwitch.h"
+
+using namespace llvm;
+using namespace llvm::remarks;
+
+Expected<Format> llvm::remarks::parseFormat(StringRef FormatStr) {
+ auto Result = StringSwitch<Format>(FormatStr)
+ .Cases("", "yaml", Format::YAML)
+ .Default(Format::Unknown);
+
+ if (Result == Format::Unknown)
+ return createStringError(std::make_error_code(std::errc::invalid_argument),
+ "Unknown remark serializer format: '%s'",
+ FormatStr.data());
+
+ return Result;
+}
diff --git a/llvm/lib/Remarks/RemarkParser.cpp b/llvm/lib/Remarks/RemarkParser.cpp
index bd83ba488d8..41ed64d022b 100644
--- a/llvm/lib/Remarks/RemarkParser.cpp
+++ b/llvm/lib/Remarks/RemarkParser.cpp
@@ -20,31 +20,35 @@
using namespace llvm;
using namespace llvm::remarks;
-static std::unique_ptr<ParserImpl> formatToParserImpl(ParserFormat Format,
+static std::unique_ptr<ParserImpl> formatToParserImpl(Format ParserFormat,
StringRef Buf) {
- switch (Format) {
- case ParserFormat::YAML:
+ switch (ParserFormat) {
+ case Format::YAML:
return llvm::make_unique<YAMLParserImpl>(Buf);
+ case Format::Unknown:
+ llvm_unreachable("Unhandled llvm::remarks::ParserFormat enum");
+ return nullptr;
};
- llvm_unreachable("Unhandled llvm::remarks::ParserFormat enum");
}
static std::unique_ptr<ParserImpl>
-formatToParserImpl(ParserFormat Format, StringRef Buf,
+formatToParserImpl(Format ParserFormat, StringRef Buf,
const ParsedStringTable &StrTab) {
- switch (Format) {
- case ParserFormat::YAML:
+ switch (ParserFormat) {
+ case Format::YAML:
return llvm::make_unique<YAMLParserImpl>(Buf, &StrTab);
+ case Format::Unknown:
+ llvm_unreachable("Unhandled llvm::remarks::ParserFormat enum");
+ return nullptr;
};
- llvm_unreachable("Unhandled llvm::remarks::ParserFormat enum");
}
-Parser::Parser(ParserFormat Format, StringRef Buf)
- : Impl(formatToParserImpl(Format, Buf)) {}
+Parser::Parser(Format ParserFormat, StringRef Buf)
+ : Impl(formatToParserImpl(ParserFormat, Buf)) {}
-Parser::Parser(ParserFormat Format, StringRef Buf,
+Parser::Parser(Format ParserFormat, StringRef Buf,
const ParsedStringTable &StrTab)
- : Impl(formatToParserImpl(Format, Buf, StrTab)) {}
+ : Impl(formatToParserImpl(ParserFormat, Buf, StrTab)) {}
Parser::~Parser() = default;
@@ -110,9 +114,8 @@ DEFINE_SIMPLE_CONVERSION_FUNCTIONS(remarks::Parser, LLVMRemarkParserRef)
extern "C" LLVMRemarkParserRef LLVMRemarkParserCreateYAML(const void *Buf,
uint64_t Size) {
- return wrap(
- new remarks::Parser(remarks::ParserFormat::YAML,
- StringRef(static_cast<const char *>(Buf), Size)));
+ return wrap(new remarks::Parser(
+ remarks::Format::YAML, StringRef(static_cast<const char *>(Buf), Size)));
}
static void handleYAMLError(remarks::YAMLParserImpl &Impl, Error E) {
diff --git a/llvm/lib/Remarks/RemarkParserImpl.h b/llvm/lib/Remarks/RemarkParserImpl.h
index 6b9329b1815..5f8c21dcdd4 100644
--- a/llvm/lib/Remarks/RemarkParserImpl.h
+++ b/llvm/lib/Remarks/RemarkParserImpl.h
@@ -19,13 +19,13 @@ namespace llvm {
namespace remarks {
/// This is used as a base for any parser implementation.
struct ParserImpl {
- explicit ParserImpl(ParserFormat Format) : Format(Format) {}
+ explicit ParserImpl(Format ParserFormat) : ParserFormat(ParserFormat) {}
// Virtual destructor prevents mismatched deletes
virtual ~ParserImpl() {}
// The parser format. This is used as a tag to safely cast between
// implementations.
- ParserFormat Format;
+ Format ParserFormat;
};
} // end namespace remarks
} // end namespace llvm
diff --git a/llvm/lib/Remarks/YAMLRemarkParser.h b/llvm/lib/Remarks/YAMLRemarkParser.h
index 9ed18eebe77..14698bbd3ca 100644
--- a/llvm/lib/Remarks/YAMLRemarkParser.h
+++ b/llvm/lib/Remarks/YAMLRemarkParser.h
@@ -127,11 +127,11 @@ struct YAMLParserImpl : public ParserImpl {
YAMLParserImpl(StringRef Buf,
Optional<const ParsedStringTable *> StrTab = None)
- : ParserImpl{ParserFormat::YAML}, YAMLParser(Buf, StrTab),
+ : ParserImpl{Format::YAML}, YAMLParser(Buf, StrTab),
YAMLIt(YAMLParser.Stream.begin()), HasErrors(false) {}
static bool classof(const ParserImpl *PI) {
- return PI->Format == ParserFormat::YAML;
+ return PI->ParserFormat == Format::YAML;
}
};
} // end namespace remarks
diff --git a/llvm/tools/llvm-opt-report/OptReport.cpp b/llvm/tools/llvm-opt-report/OptReport.cpp
index b263d9a4fb6..80d0b73664d 100644
--- a/llvm/tools/llvm-opt-report/OptReport.cpp
+++ b/llvm/tools/llvm-opt-report/OptReport.cpp
@@ -150,7 +150,7 @@ static bool readLocationInfo(LocationInfoTy &LocationInfo) {
return false;
}
- remarks::Parser Parser(remarks::ParserFormat::YAML, (*Buf)->getBuffer());
+ remarks::Parser Parser(remarks::Format::YAML, (*Buf)->getBuffer());
while (true) {
Expected<const remarks::Remark *> RemarkOrErr = Parser.getNext();
diff --git a/llvm/unittests/Remarks/YAMLRemarksParsingTest.cpp b/llvm/unittests/Remarks/YAMLRemarksParsingTest.cpp
index 6cca4c5ce8c..e3c7cdf881e 100644
--- a/llvm/unittests/Remarks/YAMLRemarksParsingTest.cpp
+++ b/llvm/unittests/Remarks/YAMLRemarksParsingTest.cpp
@@ -14,7 +14,7 @@
using namespace llvm;
template <size_t N> void parseGood(const char (&Buf)[N]) {
- remarks::Parser Parser(remarks::ParserFormat::YAML, {Buf, N - 1});
+ remarks::Parser Parser(remarks::Format::YAML, {Buf, N - 1});
Expected<const remarks::Remark *> Remark = Parser.getNext();
EXPECT_FALSE(errorToBool(Remark.takeError())); // Check for parsing errors.
EXPECT_TRUE(*Remark != nullptr); // At least one remark.
@@ -25,7 +25,7 @@ template <size_t N> void parseGood(const char (&Buf)[N]) {
template <size_t N>
bool parseExpectError(const char (&Buf)[N], const char *Error) {
- remarks::Parser Parser(remarks::ParserFormat::YAML, {Buf, N - 1});
+ remarks::Parser Parser(remarks::Format::YAML, {Buf, N - 1});
Expected<const remarks::Remark *> Remark = Parser.getNext();
EXPECT_FALSE(Remark); // Expect an error here.
@@ -354,7 +354,7 @@ TEST(YAMLRemarks, Contents) {
" - String: ' because its definition is unavailable'\n"
"\n";
- remarks::Parser Parser(remarks::ParserFormat::YAML, Buf);
+ remarks::Parser Parser(remarks::Format::YAML, Buf);
Expected<const remarks::Remark *> RemarkOrErr = Parser.getNext();
EXPECT_FALSE(errorToBool(RemarkOrErr.takeError()));
EXPECT_TRUE(*RemarkOrErr != nullptr);
@@ -516,7 +516,7 @@ TEST(YAMLRemarks, ContentsStrTab) {
115);
remarks::ParsedStringTable StrTab(StrTabBuf);
- remarks::Parser Parser(remarks::ParserFormat::YAML, Buf, StrTab);
+ remarks::Parser Parser(remarks::Format::YAML, Buf, StrTab);
Expected<const remarks::Remark *> RemarkOrErr = Parser.getNext();
EXPECT_FALSE(errorToBool(RemarkOrErr.takeError()));
EXPECT_TRUE(*RemarkOrErr != nullptr);
@@ -584,7 +584,7 @@ TEST(YAMLRemarks, ParsingBadStringTableIndex) {
StringRef StrTabBuf = StringRef("inline");
remarks::ParsedStringTable StrTab(StrTabBuf);
- remarks::Parser Parser(remarks::ParserFormat::YAML, Buf, StrTab);
+ remarks::Parser Parser(remarks::Format::YAML, Buf, StrTab);
Expected<const remarks::Remark *> Remark = Parser.getNext();
EXPECT_FALSE(Remark); // Expect an error here.
OpenPOWER on IntegriCloud