[llvm] r366216 - [Remarks][NFC] Combine ParserFormat and SerializerFormat
Francis Visoiu Mistrih via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 16 08:24:59 PDT 2019
Author: thegameg
Date: Tue Jul 16 08:24:59 2019
New Revision: 366216
URL: http://llvm.org/viewvc/llvm-project?rev=366216&view=rev
Log:
[Remarks][NFC] Combine ParserFormat and SerializerFormat
It's useless to have both.
Added:
llvm/trunk/include/llvm/Remarks/RemarkFormat.h
llvm/trunk/lib/Remarks/RemarkFormat.cpp
Modified:
llvm/trunk/include/llvm/IR/RemarkStreamer.h
llvm/trunk/include/llvm/Remarks/Remark.h
llvm/trunk/include/llvm/Remarks/RemarkParser.h
llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
llvm/trunk/lib/IR/RemarkStreamer.cpp
llvm/trunk/lib/Remarks/CMakeLists.txt
llvm/trunk/lib/Remarks/RemarkParser.cpp
llvm/trunk/lib/Remarks/RemarkParserImpl.h
llvm/trunk/lib/Remarks/YAMLRemarkParser.h
llvm/trunk/tools/llvm-opt-report/OptReport.cpp
llvm/trunk/unittests/Remarks/YAMLRemarksParsingTest.cpp
Modified: llvm/trunk/include/llvm/IR/RemarkStreamer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/RemarkStreamer.h?rev=366216&r1=366215&r2=366216&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/RemarkStreamer.h (original)
+++ llvm/trunk/include/llvm/IR/RemarkStreamer.h Tue Jul 16 08:24:59 2019
@@ -90,10 +90,6 @@ struct RemarkSetupFormatError : RemarkSe
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,
Modified: llvm/trunk/include/llvm/Remarks/Remark.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Remarks/Remark.h?rev=366216&r1=366215&r2=366216&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Remarks/Remark.h (original)
+++ llvm/trunk/include/llvm/Remarks/Remark.h Tue Jul 16 08:24:59 2019
@@ -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 {
Added: llvm/trunk/include/llvm/Remarks/RemarkFormat.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Remarks/RemarkFormat.h?rev=366216&view=auto
==============================================================================
--- llvm/trunk/include/llvm/Remarks/RemarkFormat.h (added)
+++ llvm/trunk/include/llvm/Remarks/RemarkFormat.h Tue Jul 16 08:24:59 2019
@@ -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 */
Modified: llvm/trunk/include/llvm/Remarks/RemarkParser.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Remarks/RemarkParser.h?rev=366216&r1=366215&r2=366216&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Remarks/RemarkParser.h (original)
+++ llvm/trunk/include/llvm/Remarks/RemarkParser.h Tue Jul 16 08:24:59 2019
@@ -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.
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp?rev=366216&r1=366215&r2=366216&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Tue Jul 16 08:24:59 2019
@@ -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"
Modified: llvm/trunk/lib/IR/RemarkStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/RemarkStreamer.cpp?rev=366216&r1=366215&r2=366216&view=diff
==============================================================================
--- llvm/trunk/lib/IR/RemarkStreamer.cpp (original)
+++ llvm/trunk/lib/IR/RemarkStreamer.cpp Tue Jul 16 08:24:59 2019
@@ -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(LLVMConte
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));
Modified: llvm/trunk/lib/Remarks/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Remarks/CMakeLists.txt?rev=366216&r1=366215&r2=366216&view=diff
==============================================================================
--- llvm/trunk/lib/Remarks/CMakeLists.txt (original)
+++ llvm/trunk/lib/Remarks/CMakeLists.txt Tue Jul 16 08:24:59 2019
@@ -1,5 +1,6 @@
add_llvm_library(LLVMRemarks
Remark.cpp
+ RemarkFormat.cpp
RemarkParser.cpp
RemarkStringTable.cpp
YAMLRemarkParser.cpp
Added: llvm/trunk/lib/Remarks/RemarkFormat.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Remarks/RemarkFormat.cpp?rev=366216&view=auto
==============================================================================
--- llvm/trunk/lib/Remarks/RemarkFormat.cpp (added)
+++ llvm/trunk/lib/Remarks/RemarkFormat.cpp Tue Jul 16 08:24:59 2019
@@ -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;
+}
Modified: llvm/trunk/lib/Remarks/RemarkParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Remarks/RemarkParser.cpp?rev=366216&r1=366215&r2=366216&view=diff
==============================================================================
--- llvm/trunk/lib/Remarks/RemarkParser.cpp (original)
+++ llvm/trunk/lib/Remarks/RemarkParser.cpp Tue Jul 16 08:24:59 2019
@@ -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(remar
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) {
Modified: llvm/trunk/lib/Remarks/RemarkParserImpl.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Remarks/RemarkParserImpl.h?rev=366216&r1=366215&r2=366216&view=diff
==============================================================================
--- llvm/trunk/lib/Remarks/RemarkParserImpl.h (original)
+++ llvm/trunk/lib/Remarks/RemarkParserImpl.h Tue Jul 16 08:24:59 2019
@@ -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
Modified: llvm/trunk/lib/Remarks/YAMLRemarkParser.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Remarks/YAMLRemarkParser.h?rev=366216&r1=366215&r2=366216&view=diff
==============================================================================
--- llvm/trunk/lib/Remarks/YAMLRemarkParser.h (original)
+++ llvm/trunk/lib/Remarks/YAMLRemarkParser.h Tue Jul 16 08:24:59 2019
@@ -127,11 +127,11 @@ struct YAMLParserImpl : public ParserImp
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
Modified: llvm/trunk/tools/llvm-opt-report/OptReport.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-opt-report/OptReport.cpp?rev=366216&r1=366215&r2=366216&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-opt-report/OptReport.cpp (original)
+++ llvm/trunk/tools/llvm-opt-report/OptReport.cpp Tue Jul 16 08:24:59 2019
@@ -150,7 +150,7 @@ static bool readLocationInfo(LocationInf
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();
Modified: llvm/trunk/unittests/Remarks/YAMLRemarksParsingTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Remarks/YAMLRemarksParsingTest.cpp?rev=366216&r1=366215&r2=366216&view=diff
==============================================================================
--- llvm/trunk/unittests/Remarks/YAMLRemarksParsingTest.cpp (original)
+++ llvm/trunk/unittests/Remarks/YAMLRemarksParsingTest.cpp Tue Jul 16 08:24:59 2019
@@ -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
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, ParsingBadStringTableI
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.
More information about the llvm-commits
mailing list