28 Commits

Author SHA1 Message Date
Francis Visoiu Mistrih
381c09ac35 [Remarks] Add support for prepending a path to external files
This helps with testing and debugging for paths that are assumed
absolute.

It also uses a FileError to provide the file path it's trying to open.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@375008 91177308-0d34-0410-b5e6-96231b3b80d8
2019-10-16 15:40:59 +00:00
Francis Visoiu Mistrih
b68f7fd8cd [Remarks] Add parser for bitstream remarks
The bitstream remark serializer landed in r367372.

This adds a bitstream remark parser that parser bitstream remark files
to llvm::remarks::Remark objects through the RemarkParser interface.

A few interesting things to point out:

* There are parsing helpers to parse the different types of blocks
* The main parsing helper allows us to parse remark metadata and open an
external file containing the encoded remarks
* This adds a dependency from the Remarks library to the BitstreamReader
library
* The testing strategy is to create a remark entry through YAML, parse
it, serialize it to bitstream, parse that back and compare the objects.
* There are close to no tests for malformed bitstream remarks, due to
the lack of textual format for the bitstream format.
* This adds a new C API for parsing bitstream remarks:
LLVMRemarkParserCreateBitstream.
* This bumps the REMARKS_API_VERSION to 1.

Differential Revision: https://reviews.llvm.org/D67134

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@371429 91177308-0d34-0410-b5e6-96231b3b80d8
2019-09-09 17:43:50 +00:00
Benjamin Kramer
8a67530447 Do a sweep of symbol internalization. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@369803 91177308-0d34-0410-b5e6-96231b3b80d8
2019-08-23 19:59:23 +00:00
Jonas Devlieghere
114087caa6 [llvm] Migrate llvm::make_unique to std::make_unique
Now that we've moved to C++14, we no longer need the llvm::make_unique
implementation from STLExtras.h. This patch is a mechanical replacement
of (hopefully) all the llvm::make_unique instances across the monorepo.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@369013 91177308-0d34-0410-b5e6-96231b3b80d8
2019-08-15 15:54:37 +00:00
Francis Visoiu Mistrih
fcf99c532d Reland: [Remarks] Add an LLVM-bitstream-based remark serializer
Add a new serializer, using a binary format based on the LLVM bitstream
format.

This format provides a way to serialize the remarks in two modes:

1) Separate mode: the metadata is separate from the remark entries.
2) Standalone mode: the metadata and the remark entries are in the same
file.

The format contains:

* a meta block: container version, container type, string table,
external file path, remark version
* a remark block: type, remark name, pass name, function name, debug
file, debug line, debug column, hotness, arguments (key, value, debug
file, debug line, debug column)

A string table is required for this format, which will be dumped in the
meta block to be consumed before parsing the remark blocks.

On clang itself, we noticed a size reduction of 13.4x compared to YAML,
and a compile-time reduction of between 1.7% and 3.5% on CTMark.

Differential Revision: https://reviews.llvm.org/D63466

Original llvm-svn: 367364
Revert llvm-svn: 367370

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@367372 91177308-0d34-0410-b5e6-96231b3b80d8
2019-07-31 00:13:51 +00:00
Francis Visoiu Mistrih
16956a6979 Revert "[Remarks] Add an LLVM-bitstream-based remark serializer"
This reverts commit r367364.

Breaks some bots: http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-gn/builds/3161/steps/annotate/logs/stdio

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@367370 91177308-0d34-0410-b5e6-96231b3b80d8
2019-07-31 00:01:34 +00:00
Francis Visoiu Mistrih
6038bea1b8 [Remarks] Add an LLVM-bitstream-based remark serializer
Add a new serializer, using a binary format based on the LLVM bitstream
format.

This format provides a way to serialize the remarks in two modes:

1) Separate mode: the metadata is separate from the remark entries.
2) Standalone mode: the metadata and the remark entries are in the same
file.

The format contains:

* a meta block: container version, container type, string table,
external file path, remark version
* a remark block: type, remark name, pass name, function name, debug
file, debug line, debug column, hotness, arguments (key, value, debug
file, debug line, debug column)

A string table is required for this format, which will be dumped in the
meta block to be consumed before parsing the remark blocks.

On clang itself, we noticed a size reduction of 13.4x compared to YAML,
and a compile-time reduction of between 1.7% and 3.5% on CTMark.

Differential Revision: https://reviews.llvm.org/D63466

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@367364 91177308-0d34-0410-b5e6-96231b3b80d8
2019-07-30 23:11:57 +00:00
Francis Visoiu Mistrih
1883d950b1 [Remarks] Silence Wreturn-type warning
Shows up here: http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fuzzer/builds/27771/steps/annotate/logs/stdio.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@367162 91177308-0d34-0410-b5e6-96231b3b80d8
2019-07-26 22:42:54 +00:00
Francis Visoiu Mistrih
02582ef3db Reland: [Remarks] Support parsing remark metadata in the YAML remark parser
This adds support to the yaml remark parser to be able to parse remarks
directly from the metadata.

This supports parsing separate metadata and following the external file
with the associated metadata, and also a standalone file containing
metadata + remarks all together.

Original llvm-svn: 367148
Revert llvm-svn: 367151

This has a fix for gcc builds.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@367155 91177308-0d34-0410-b5e6-96231b3b80d8
2019-07-26 21:02:02 +00:00
Francis Visoiu Mistrih
a0eba5f776 Revert "[Remarks] Support parsing remark metadata in the YAML remark parser"
This reverts r367148.

Seems to fail on
http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fuzzer/builds/27768.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@367151 91177308-0d34-0410-b5e6-96231b3b80d8
2019-07-26 20:54:44 +00:00
Francis Visoiu Mistrih
aae2cef176 [Remarks] Support parsing remark metadata in the YAML remark parser
This adds support to the yaml remark parser to be able to parse remarks
directly from the metadata.

This supports parsing separate metadata and following the external file
with the associated metadata, and also a standalone file containing
metadata + remarks all together.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@367148 91177308-0d34-0410-b5e6-96231b3b80d8
2019-07-26 20:11:53 +00:00
Francis Visoiu Mistrih
a232c74dcf [Remarks][NFC] Rename remarks::Parser to remarks::RemarkParser
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@366965 91177308-0d34-0410-b5e6-96231b3b80d8
2019-07-25 00:16:56 +00:00
Haojian Wu
097fe86031 [Remark] Suppress the "-Wreturn-type" compiler warning, NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@366874 91177308-0d34-0410-b5e6-96231b3b80d8
2019-07-24 07:55:01 +00:00
Francis Visoiu Mistrih
ffbfdbd2bf [Remarks] String tables should be move-only
Copying them is expensive. This allows the tables to be moved around at
lower cost, and allows a remarks::StringTable to be constructed from
a remarks::ParsedStringTable.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@366864 91177308-0d34-0410-b5e6-96231b3b80d8
2019-07-23 22:50:08 +00:00
Francis Visoiu Mistrih
f802102dc4 [Remarks] Introduce a new format: yaml-strtab
This exposes better support to use a string table with a format through
an actual new remark::Format, called yaml-strtab.

This can now be used with -fsave-optimization-record=yaml-strtab.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@366849 91177308-0d34-0410-b5e6-96231b3b80d8
2019-07-23 20:42:46 +00:00
Michael Liao
f8b274f2cb Fix -Wreturn-type warning. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@366251 91177308-0d34-0410-b5e6-96231b3b80d8
2019-07-16 19:59:08 +00:00
Francis Visoiu Mistrih
00c0e0040f [Remarks] Simplify and refactor the RemarkParser interface
Before, everything was based on some kind of type erased parser
implementation which container a lot of boilerplate code when multiple
formats were to be supported.

This simplifies it by:

* the remark now owns its arguments
* *always* returning an error from the implementation side
* working around the way the YAML parser reports errors: catch them through
callbacks and re-insert them in a proper llvm::Error
* add a CParser wrapper that is used when implementing the C API to
avoid cluttering the C++ API with useless state
* LLVMRemarkParserGetNext now returns an object that needs to be
released to avoid leaking resources
* add a new API to dispose of a remark entry: LLVMRemarkEntryDispose

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@366217 91177308-0d34-0410-b5e6-96231b3b80d8
2019-07-16 15:25:05 +00:00
Francis Visoiu Mistrih
ce4ba232b0 [Remarks][NFC] Combine ParserFormat and SerializerFormat
It's useless to have both.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@366216 91177308-0d34-0410-b5e6-96231b3b80d8
2019-07-16 15:24:59 +00:00
Simon Pilgrim
948545f15e Fix MSVC "not all control paths return a value" warnings. NFCI.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@365119 91177308-0d34-0410-b5e6-96231b3b80d8
2019-07-04 09:46:06 +00:00
Mikael Holmen
1934a3e523 [Remarks] Silence gcc warning by catching unhandled values in switches
Without this fix gcc (7.4) complains with
 ../lib/Remarks/RemarkParser.cpp: In function 'std::unique_ptr<llvm::remarks::ParserImpl> formatToParserImpl(llvm::remarks::ParserFormat, llvm::StringRef)':
 ../lib/Remarks/RemarkParser.cpp:29:1: error: control reaches end of non-void function [-Werror=return-type]
  }
  ^
 ../lib/Remarks/RemarkParser.cpp: In function 'std::unique_ptr<llvm::remarks::ParserImpl> formatToParserImpl(llvm::remarks::ParserFormat, llvm::StringRef, const llvm::remarks::ParsedStringTable&)':
 ../lib/Remarks/RemarkParser.cpp:38:1: error: control reaches end of non-void function [-Werror=return-type]
  }
  ^

The Format enum currently only contains the value YAML which is indeed
already handled in the switches, but gcc complains anyway.

Adding a default case with an llvm_unreachable silences gcc.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@365118 91177308-0d34-0410-b5e6-96231b3b80d8
2019-07-04 09:29:18 +00:00
Francis Visoiu Mistrih
c289f25a0f [Remarks] Require an explicit format to the parser
Make the parser require an explicit format.

This allows new formats to be easily added by following YAML as an
example.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@365102 91177308-0d34-0410-b5e6-96231b3b80d8
2019-07-04 00:31:03 +00:00
Francis Visoiu Mistrih
95095ee2f4 [Remarks][NFC] Move the string table parsing out of the parser constructor
Make the parser take an already-parsed string table.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@365101 91177308-0d34-0410-b5e6-96231b3b80d8
2019-07-04 00:30:58 +00:00
Francis Visoiu Mistrih
04dcbb5165 [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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@359050 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-24 00:06:24 +00:00
Francis Visoiu Mistrih
ae5245f08c Reland "[Remarks] Add a new Remark / RemarkParser abstraction"
This adds a Remark class that allows us to share code when working with
remarks.

The C API has been updated to reflect this. Instead of the parser
generating C structs, it's now using a C++ object that is used through
opaque pointers in C. This gives us much more flexibility on what
changes we can make to the internal state of the object and interacts
much better with scenarios where the library is used through dlopen.

* C API updates:
  * move from C structs to opaque pointers and functions
  * the remark type is now an enum instead of a string
* unit tests updates:
  * use mostly the C++ API
  * keep one test for the C API
  * rename to YAMLRemarksParsingTest
* a typo was fixed: AnalysisFPCompute -> AnalysisFPCommute.
* a new error message was added: "expected a remark tag."
* llvm-opt-report has been updated to use the C++ parser instead of the
C API

Differential Revision: https://reviews.llvm.org/D59049

Original llvm-svn: 356491

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@356519 91177308-0d34-0410-b5e6-96231b3b80d8
2019-03-19 21:11:07 +00:00
Francis Visoiu Mistrih
7feeb42225 Revert "[Remarks] Add a new Remark / RemarkParser abstraction"
This reverts commit 51dc6a8c84cd6a58562e320e1828a0158dbbf750.

Breaks
http://lab.llvm.org:8011/builders/clang-cmake-x86_64-sde-avx512-linux/builds/20034/steps/build%20stage%201/logs/stdio.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@356492 91177308-0d34-0410-b5e6-96231b3b80d8
2019-03-19 18:21:43 +00:00
Francis Visoiu Mistrih
2e8758fd51 [Remarks] Add a new Remark / RemarkParser abstraction
This adds a Remark class that allows us to share code when working with
remarks.

The C API has been updated to reflect this. Instead of the parser
generating C structs, it's now using a C++ object that is used through
opaque pointers in C. This gives us much more flexibility on what
changes we can make to the internal state of the object and interacts
much better with scenarios where the library is used through dlopen.

* C API updates:
  * move from C structs to opaque pointers and functions
  * the remark type is now an enum instead of a string
* unit tests updates:
  * use mostly the C++ API
  * keep one test for the C API
  * rename to YAMLRemarksParsingTest
* a typo was fixed: AnalysisFPCompute -> AnalysisFPCommute.
* a new error message was added: "expected a remark tag."
* llvm-opt-report has been updated to use the C++ parser instead of the
C API

Differential Revision: https://reviews.llvm.org/D59049

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@356491 91177308-0d34-0410-b5e6-96231b3b80d8
2019-03-19 18:09:51 +00:00
Francis Visoiu Mistrih
f8d95d2d94 [Remarks][NFC] Rename RemarkParser to YAMLRemarkParser
Rename it to reflect that it's parsing YAML remarks.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@355441 91177308-0d34-0410-b5e6-96231b3b80d8
2019-03-05 20:50:35 +00:00
Francis Visoiu Mistrih
f43cce5263 [OptRemarks] Make OptRemarks more generic: rename OptRemarks to Remarks
Getting rid of the name "optimization remarks" for anything that
involves handling remarks on the client side.

It's safer to do this now, before we get stuck with that name in all the
APIs and public interfaces we decide to export to users in the future.

This renames llvm/tools/opt-remarks to llvm/tools/remarks-shlib, and now
generates `libRemarks.dylib` instead of `libOptRemarks.dylib`.

Differential Revision: https://reviews.llvm.org/D58535

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@355439 91177308-0d34-0410-b5e6-96231b3b80d8
2019-03-05 20:45:17 +00:00