[Frontend][Diagnostics] Improve emitting diagnostic information #5581
+160
−97
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.
Summary
This PR enhances the current implementation for emitting diagnostic remarks by introducing a unified handler in
ir.cc
. This handler manages diagnostic information more effectively and disables the emission of IRs unless explicitly requested by the user. TheMLIR_ENABLE_DIAGNOSTICS
environment variable now controls all diagnostic emission settings, accepting one or more values from{warnings, remarks, stacktraces, operations}
, separated by commas. Detailed usage instructions are available in the README.Background
Previously, a new default LLVM
SourceManager
was configured innvidia/backend/compiler.py
to support remarks, applied in bothmake_ttgir
andmake_llir
. However, a custom handler already existed inir.cc
, and a more robust design should extend this handler rather than create a new one.Changes
Unified Handler: Inspired by LLVM upstream [PR 117669]([MLIR][mlir-opt] add support for disabling diagnostics llvm/llvm-project#117669), this PR implements a similar custom handler that supports various severity levels. The
MLIR_ENABLE_DIAGNOSTICS
environment variable now specifies the severity level:warnings
for warnings and errors, andremarks
for remarks, warnings, and errors.IR Emission Control: By default, the MLIR diagnostic API emits IRs, which can clutter error messages or performance remarks. This PR suppresses IR emission unless explicitly enabled by the user, improving the readability of error messages and performance remarks. Users can specify
MLIR_ENABLE_DIAGNOSTICS=remarks,operations
to include IR operations in remarks.Stacktraces: Previously, setting
MLIR_ENABLE_DIAGNOSTICS=1
enabled all diagnostic information with stacktraces. Now, thestacktraces
parameter specifically enables stacktraces. For example,MLIR_ENABLE_DIAGNOSTICS=remarks,operations,stacktraces
enables IR operations and stacktraces, displaying all remarks, warnings, and errors.Testing: Updated existing Python tests to verify that combinations of operations and stacktraces are emitted successfully.
Future Work
New contributor declaration
I am not making a trivial change, such as fixing a typo in a comment.
I have written a PR description following these
rules.
I have run
pre-commit run --from-ref origin/main --to-ref HEAD
.Select one of the following.
/python/test
for end-to-end testsSelect one of the following.
lit
tests.lit
tests I have added follow these best practices,including the "tests should be minimal" section. (Usually running Python code
and using the instructions it generates is not minimal.)