-
Notifications
You must be signed in to change notification settings - Fork 15k
[MLIR] Improve Remark documentation to include mlir-opt usage #159284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
grypp
wants to merge
2
commits into
llvm:main
Choose a base branch
from
grypp:remark-more-doc
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -96,8 +96,16 @@ Neutral analysis results. | |
|
|
||
| ## Emitting Remarks | ||
|
|
||
| The `remark::*` helpers return an **in-flight remark**. | ||
| You append strings or key–value metrics using `<<`. | ||
| The `remark::*` helpers return an **`InFlightRemark`**. You can append strings | ||
| or key–value metrics using the `<<` operator. | ||
|
|
||
| By default, the remark is emitted as soon as the `InFlightRemark` object is | ||
| destroyed (typically at the end of its scope). However, it can sometimes be | ||
| useful to postpone emitting the remark until the end of the compilation—for example, | ||
| to collect all remarks, sort them, and emit them differently later. | ||
|
|
||
| If this behavior is desired, the `RemarkEngine` can be used to store postponed remarks. | ||
| [See this example of postponing remark emission](#example-postpone-remarks-emitting). | ||
|
|
||
| ### Remark Options | ||
|
|
||
|
|
@@ -108,8 +116,9 @@ When constructing a remark, you typically provide four fields that are `StringRe | |
| 3. **Sub-category** – more fine-grained classification | ||
| 4. **Function name** – the function where the remark originates | ||
|
|
||
| ### Examples | ||
|
|
||
| ### Example | ||
| #### Emitting remarks | ||
|
|
||
| ```c++ | ||
| #include "mlir/IR/Remarks.h" | ||
|
|
@@ -145,6 +154,19 @@ LogicalResult MyPass::runOnOperation() { | |
| } | ||
| ``` | ||
|
|
||
| #### Example: Postpone remarks emitting | ||
|
|
||
| `RemarkOpts` has `postpone` option. When it is set, the remark emission will be | ||
| postponed until the end of the compilation. | ||
|
|
||
| ```c++ | ||
|
|
||
| remark::passed(loc, remark::RemarkOpts::name("") | ||
| .category(categoryLoopunroll) | ||
| .subCategory(myPassname2) | ||
| .postpone()) << "loop is unrolled"; | ||
| ``` | ||
grypp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| *** | ||
|
|
||
| ### Metrics and Shortcuts | ||
|
|
@@ -189,7 +211,42 @@ metric("Remark", "vectorized loop") | |
|
|
||
| *** | ||
|
|
||
| ## Enabling Remarks | ||
| ## Enabling Remarks with `mlir-opt` | ||
|
|
||
| `mlir-opt` provides flags to enable and configure remarks. The available flags | ||
| are shown below: | ||
|
|
||
| ```bash | ||
| $> mlir-opt --help | ||
| ... | ||
| Remark Options: | ||
| Filter remarks by regular expression (llvm::Regex syntax). | ||
|
|
||
| --remark-format=<value> - Specify the format for remark output. | ||
| =emitRemark - Print as emitRemark to the command line | ||
| =yaml - Print as a YAML file | ||
| =bitstream - Print as a bitstream file | ||
| --remarks-filter=<string> - Show all remarks: passed, missed, failed, analysis | ||
| --remarks-filter-analyse=<string> - Show analysis remarks | ||
| --remarks-filter-failed=<string> - Show failed remarks | ||
| --remarks-filter-missed=<string> - Show missed remarks | ||
| --remarks-filter-passed=<string> - Show passed remarks | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is still the same issue with the help messages: "Show xxxx" is not well descriptive for something that is a filter. |
||
| --remarks-output-file=<string> - Output file for YAML and bitstream remark formats (default: mlir-remarks.yaml or mlir-remarks.bitstream) | ||
| ``` | ||
|
|
||
| There are five filter flags to select specific categories. The | ||
| `--remarks-filter` flag is a general shortcut that applies to all remark | ||
| categories. Their usage is as follows: | ||
|
|
||
| ```bash | ||
| # This will only match remarks in the "my-interesting-category" category | ||
| mlir-opt --remarks-filter="my-interesting-category" | ||
|
|
||
| # You can also use "*" to match categories starting with "my" | ||
| mlir-opt --remarks-filter="my*" | ||
| ``` | ||
|
|
||
| ## Enabling Remarks for downstream compilers via APIs | ||
|
|
||
| ### 1. **With LLVMRemarkStreamer (YAML or Bitstream)** | ||
|
|
||
|
|
||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should document when/why this is useful, not just "what". It's not obvious to me why a remark author would want to use this and when?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wrote it here:
https://github.com/grypp/llvm-project/blob/cc673be6642b49c2396e07b86c4e4e52c6b0e7a4/mlir/docs/Remarks.md?plain=1#L102-L105
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Postponing will be more useful with my new PR.
The new PR allows dropping or replacing earlier remarks when using postponing.
Here’s an example:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's still not clear to me how this is a decision of the remark author, and the implicit coupling that can exist between the remark and the consumer here?