Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Why
LLVM has the possibility of outputting detailed logs of which optimizations it tried to apply and which failed.
The feature is relatively unknown, but I found it pretty useful to understand what LLVM is actually doing on complex C++ code.
I propose to expose this LLVM feature in
zig build-xxx
.References:
https://www.llvm.org/docs/Remarks.html
https://www.youtube.com/watch?v=qmEsx4MbKoc
Example
The default remark serializer implemented in LLVM generates a very verbose YAML file,
but one can use llvm "opt-viewer" to convert it to more readable html file merging the souce code and annotations.
Here is an example for the following simple Zig program:
Implememtation choices
llc
exposes 5 flags for remarks:I chose to only add an
-femit-opt-remarks
flag to Zig, mimicking-femit-asm
or-femit-llvm-ir
behavior.The format is YAML by default with LLVM and the tools I saw to display the information seems to assume YAML.
This seems reasonable for a first iteration.
I'm not sure there is a lot of value of chosing at compile time which remarks should/shouldn't be written, I feel this filtering is better suited for the display stage. For info the remarks generated for Zig itself is a 600Mb yaml file.
Last;y AFAIK Zig doesn't have PGO support, and if it did the combination of PGO + remarks flag should default to include the PGO in the remarks.
Future work
Optimization remarks should also be collected during LTO.