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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_REMARKS_REMARK_PARSER_H
|
|
|
|
#define LLVM_REMARKS_REMARK_PARSER_H
|
|
|
|
|
[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 {
|
|
|
|
|
|
|
|
struct ParserImpl;
|
2019-07-04 02:30:58 +02:00
|
|
|
struct ParsedStringTable;
|
2019-03-19 22:11:07 +01:00
|
|
|
|
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.
|
|
|
|
struct Parser {
|
2019-07-16 17:25:05 +02:00
|
|
|
/// The format of the parser.
|
|
|
|
Format ParserFormat;
|
2019-03-19 22:11:07 +01:00
|
|
|
|
2019-07-16 17:25:05 +02:00
|
|
|
Parser(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-16 17:25:05 +02:00
|
|
|
virtual ~Parser() = 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;
|
|
|
|
/// Collection of offsets in the buffer for each string entry.
|
|
|
|
SmallVector<size_t, 8> Offsets;
|
|
|
|
|
2019-07-04 02:30:58 +02:00
|
|
|
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
|
|
|
ParsedStringTable(StringRef Buffer);
|
|
|
|
};
|
|
|
|
|
2019-07-23 22:42:46 +02:00
|
|
|
Expected<std::unique_ptr<Parser>> createRemarkParser(Format ParserFormat,
|
|
|
|
StringRef Buf);
|
|
|
|
|
2019-07-16 17:25:05 +02:00
|
|
|
Expected<std::unique_ptr<Parser>>
|
|
|
|
createRemarkParser(Format ParserFormat, StringRef Buf,
|
2019-07-23 22:42:46 +02:00
|
|
|
const ParsedStringTable &StrTab);
|
2019-07-16 17:25:05 +02:00
|
|
|
|
2019-03-19 22:11:07 +01:00
|
|
|
} // end namespace remarks
|
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif /* LLVM_REMARKS_REMARK_PARSER_H */
|