2019-03-19 22:11:07 +01:00
|
|
|
//===-- llvm/Remarks/Remark.h - The remark type -----------------*- 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 provides an interface for parsing remarks in LLVM.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2021-02-06 06:02:06 +01:00
|
|
|
#ifndef LLVM_REMARKS_REMARKPARSER_H
|
|
|
|
#define LLVM_REMARKS_REMARKPARSER_H
|
2019-03-19 22:11:07 +01:00
|
|
|
|
[Remarks] Add string deduplication using a string table
* Add support for uniquing strings in the remark streamer and emitting the string table in the remarks section.
* Add parsing support for the string table in the RemarkParser.
From this remark:
```
--- !Missed
Pass: inline
Name: NoDefinition
DebugLoc: { File: 'test-suite/SingleSource/UnitTests/2002-04-17-PrintfChar.c',
Line: 7, Column: 3 }
Function: printArgsNoRet
Args:
- Callee: printf
- String: ' will not be inlined into '
- Caller: printArgsNoRet
DebugLoc: { File: 'test-suite/SingleSource/UnitTests/2002-04-17-PrintfChar.c',
Line: 6, Column: 0 }
- String: ' because its definition is unavailable'
...
```
to:
```
--- !Missed
Pass: 0
Name: 1
DebugLoc: { File: 3, Line: 7, Column: 3 }
Function: 2
Args:
- Callee: 4
- String: 5
- Caller: 2
DebugLoc: { File: 3, Line: 6, Column: 0 }
- String: 6
...
```
And the string table in the .remarks/__remarks section containing:
```
inline\0NoDefinition\0printArgsNoRet\0
test-suite/SingleSource/UnitTests/2002-04-17-PrintfChar.c\0printf\0
will not be inlined into \0 because its definition is unavailable\0
```
This is mostly supposed to be used for testing purposes, but it gives us
a 2x reduction in the remark size, and is an incremental change for the
updates to the remarks file format.
Differential Revision: https://reviews.llvm.org/D60227
llvm-svn: 359050
2019-04-24 02:06:24 +02:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2019-03-19 22:11:07 +01:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
#include "llvm/Remarks/Remark.h"
|
2019-07-16 17:24:59 +02:00
|
|
|
#include "llvm/Remarks/RemarkFormat.h"
|
2019-03-19 22:11:07 +01:00
|
|
|
#include "llvm/Support/Error.h"
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
namespace remarks {
|
|
|
|
|
2019-07-16 17:25:05 +02:00
|
|
|
class EndOfFileError : public ErrorInfo<EndOfFileError> {
|
|
|
|
public:
|
|
|
|
static char ID;
|
|
|
|
|
|
|
|
EndOfFileError() {}
|
|
|
|
|
|
|
|
void log(raw_ostream &OS) const override { OS << "End of file reached."; }
|
|
|
|
std::error_code convertToErrorCode() const override {
|
|
|
|
return inconvertibleErrorCode();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-03-19 22:11:07 +01:00
|
|
|
/// Parser used to parse a raw buffer to remarks::Remark objects.
|
2019-07-25 02:16:56 +02:00
|
|
|
struct RemarkParser {
|
2019-07-16 17:25:05 +02:00
|
|
|
/// The format of the parser.
|
|
|
|
Format ParserFormat;
|
2019-10-16 17:40:59 +02:00
|
|
|
/// Path to prepend when opening an external remark file.
|
|
|
|
std::string ExternalFilePrependPath;
|
2019-03-19 22:11:07 +01:00
|
|
|
|
2019-07-25 02:16:56 +02:00
|
|
|
RemarkParser(Format ParserFormat) : ParserFormat(ParserFormat) {}
|
[Remarks] Add string deduplication using a string table
* Add support for uniquing strings in the remark streamer and emitting the string table in the remarks section.
* Add parsing support for the string table in the RemarkParser.
From this remark:
```
--- !Missed
Pass: inline
Name: NoDefinition
DebugLoc: { File: 'test-suite/SingleSource/UnitTests/2002-04-17-PrintfChar.c',
Line: 7, Column: 3 }
Function: printArgsNoRet
Args:
- Callee: printf
- String: ' will not be inlined into '
- Caller: printArgsNoRet
DebugLoc: { File: 'test-suite/SingleSource/UnitTests/2002-04-17-PrintfChar.c',
Line: 6, Column: 0 }
- String: ' because its definition is unavailable'
...
```
to:
```
--- !Missed
Pass: 0
Name: 1
DebugLoc: { File: 3, Line: 7, Column: 3 }
Function: 2
Args:
- Callee: 4
- String: 5
- Caller: 2
DebugLoc: { File: 3, Line: 6, Column: 0 }
- String: 6
...
```
And the string table in the .remarks/__remarks section containing:
```
inline\0NoDefinition\0printArgsNoRet\0
test-suite/SingleSource/UnitTests/2002-04-17-PrintfChar.c\0printf\0
will not be inlined into \0 because its definition is unavailable\0
```
This is mostly supposed to be used for testing purposes, but it gives us
a 2x reduction in the remark size, and is an incremental change for the
updates to the remarks file format.
Differential Revision: https://reviews.llvm.org/D60227
llvm-svn: 359050
2019-04-24 02:06:24 +02:00
|
|
|
|
2019-07-16 17:25:05 +02:00
|
|
|
/// If no error occurs, this returns a valid Remark object.
|
|
|
|
/// If an error of type EndOfFileError occurs, it is safe to recover from it
|
|
|
|
/// by stopping the parsing.
|
|
|
|
/// If any other error occurs, it should be propagated to the user.
|
|
|
|
/// The pointer should never be null.
|
|
|
|
virtual Expected<std::unique_ptr<Remark>> next() = 0;
|
2019-03-19 22:11:07 +01:00
|
|
|
|
2019-07-25 02:16:56 +02:00
|
|
|
virtual ~RemarkParser() = default;
|
2019-03-19 22:11:07 +01:00
|
|
|
};
|
|
|
|
|
[Remarks] Add string deduplication using a string table
* Add support for uniquing strings in the remark streamer and emitting the string table in the remarks section.
* Add parsing support for the string table in the RemarkParser.
From this remark:
```
--- !Missed
Pass: inline
Name: NoDefinition
DebugLoc: { File: 'test-suite/SingleSource/UnitTests/2002-04-17-PrintfChar.c',
Line: 7, Column: 3 }
Function: printArgsNoRet
Args:
- Callee: printf
- String: ' will not be inlined into '
- Caller: printArgsNoRet
DebugLoc: { File: 'test-suite/SingleSource/UnitTests/2002-04-17-PrintfChar.c',
Line: 6, Column: 0 }
- String: ' because its definition is unavailable'
...
```
to:
```
--- !Missed
Pass: 0
Name: 1
DebugLoc: { File: 3, Line: 7, Column: 3 }
Function: 2
Args:
- Callee: 4
- String: 5
- Caller: 2
DebugLoc: { File: 3, Line: 6, Column: 0 }
- String: 6
...
```
And the string table in the .remarks/__remarks section containing:
```
inline\0NoDefinition\0printArgsNoRet\0
test-suite/SingleSource/UnitTests/2002-04-17-PrintfChar.c\0printf\0
will not be inlined into \0 because its definition is unavailable\0
```
This is mostly supposed to be used for testing purposes, but it gives us
a 2x reduction in the remark size, and is an incremental change for the
updates to the remarks file format.
Differential Revision: https://reviews.llvm.org/D60227
llvm-svn: 359050
2019-04-24 02:06:24 +02:00
|
|
|
/// In-memory representation of the string table parsed from a buffer (e.g. the
|
|
|
|
/// remarks section).
|
|
|
|
struct ParsedStringTable {
|
|
|
|
/// The buffer mapped from the section contents.
|
|
|
|
StringRef Buffer;
|
2019-07-24 00:50:08 +02:00
|
|
|
/// This object has high changes to be std::move'd around, so don't use a
|
|
|
|
/// SmallVector for once.
|
|
|
|
std::vector<size_t> Offsets;
|
[Remarks] Add string deduplication using a string table
* Add support for uniquing strings in the remark streamer and emitting the string table in the remarks section.
* Add parsing support for the string table in the RemarkParser.
From this remark:
```
--- !Missed
Pass: inline
Name: NoDefinition
DebugLoc: { File: 'test-suite/SingleSource/UnitTests/2002-04-17-PrintfChar.c',
Line: 7, Column: 3 }
Function: printArgsNoRet
Args:
- Callee: printf
- String: ' will not be inlined into '
- Caller: printArgsNoRet
DebugLoc: { File: 'test-suite/SingleSource/UnitTests/2002-04-17-PrintfChar.c',
Line: 6, Column: 0 }
- String: ' because its definition is unavailable'
...
```
to:
```
--- !Missed
Pass: 0
Name: 1
DebugLoc: { File: 3, Line: 7, Column: 3 }
Function: 2
Args:
- Callee: 4
- String: 5
- Caller: 2
DebugLoc: { File: 3, Line: 6, Column: 0 }
- String: 6
...
```
And the string table in the .remarks/__remarks section containing:
```
inline\0NoDefinition\0printArgsNoRet\0
test-suite/SingleSource/UnitTests/2002-04-17-PrintfChar.c\0printf\0
will not be inlined into \0 because its definition is unavailable\0
```
This is mostly supposed to be used for testing purposes, but it gives us
a 2x reduction in the remark size, and is an incremental change for the
updates to the remarks file format.
Differential Revision: https://reviews.llvm.org/D60227
llvm-svn: 359050
2019-04-24 02:06:24 +02:00
|
|
|
|
|
|
|
ParsedStringTable(StringRef Buffer);
|
2019-07-24 00:50:08 +02:00
|
|
|
/// Disable copy.
|
|
|
|
ParsedStringTable(const ParsedStringTable &) = delete;
|
|
|
|
ParsedStringTable &operator=(const ParsedStringTable &) = delete;
|
|
|
|
/// Should be movable.
|
|
|
|
ParsedStringTable(ParsedStringTable &&) = default;
|
|
|
|
ParsedStringTable &operator=(ParsedStringTable &&) = default;
|
|
|
|
|
|
|
|
size_t size() const { return Offsets.size(); }
|
|
|
|
Expected<StringRef> operator[](size_t Index) const;
|
[Remarks] Add string deduplication using a string table
* Add support for uniquing strings in the remark streamer and emitting the string table in the remarks section.
* Add parsing support for the string table in the RemarkParser.
From this remark:
```
--- !Missed
Pass: inline
Name: NoDefinition
DebugLoc: { File: 'test-suite/SingleSource/UnitTests/2002-04-17-PrintfChar.c',
Line: 7, Column: 3 }
Function: printArgsNoRet
Args:
- Callee: printf
- String: ' will not be inlined into '
- Caller: printArgsNoRet
DebugLoc: { File: 'test-suite/SingleSource/UnitTests/2002-04-17-PrintfChar.c',
Line: 6, Column: 0 }
- String: ' because its definition is unavailable'
...
```
to:
```
--- !Missed
Pass: 0
Name: 1
DebugLoc: { File: 3, Line: 7, Column: 3 }
Function: 2
Args:
- Callee: 4
- String: 5
- Caller: 2
DebugLoc: { File: 3, Line: 6, Column: 0 }
- String: 6
...
```
And the string table in the .remarks/__remarks section containing:
```
inline\0NoDefinition\0printArgsNoRet\0
test-suite/SingleSource/UnitTests/2002-04-17-PrintfChar.c\0printf\0
will not be inlined into \0 because its definition is unavailable\0
```
This is mostly supposed to be used for testing purposes, but it gives us
a 2x reduction in the remark size, and is an incremental change for the
updates to the remarks file format.
Differential Revision: https://reviews.llvm.org/D60227
llvm-svn: 359050
2019-04-24 02:06:24 +02:00
|
|
|
};
|
|
|
|
|
2019-07-25 02:16:56 +02:00
|
|
|
Expected<std::unique_ptr<RemarkParser>> createRemarkParser(Format ParserFormat,
|
|
|
|
StringRef Buf);
|
2019-07-23 22:42:46 +02:00
|
|
|
|
2019-07-25 02:16:56 +02:00
|
|
|
Expected<std::unique_ptr<RemarkParser>>
|
|
|
|
createRemarkParser(Format ParserFormat, StringRef Buf,
|
|
|
|
ParsedStringTable StrTab);
|
2019-07-16 17:25:05 +02:00
|
|
|
|
2019-07-26 23:02:02 +02:00
|
|
|
Expected<std::unique_ptr<RemarkParser>>
|
|
|
|
createRemarkParserFromMeta(Format ParserFormat, StringRef Buf,
|
2019-10-16 17:40:59 +02:00
|
|
|
Optional<ParsedStringTable> StrTab = None,
|
|
|
|
Optional<StringRef> ExternalFilePrependPath = None);
|
2019-07-26 23:02:02 +02:00
|
|
|
|
2019-03-19 22:11:07 +01:00
|
|
|
} // end namespace remarks
|
|
|
|
} // end namespace llvm
|
|
|
|
|
2021-02-06 06:02:06 +01:00
|
|
|
#endif // LLVM_REMARKS_REMARKPARSER_H
|