Skip to content

[MLIR][mlir-opt] add support for disabling diagnostics #117669

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

Merged
merged 4 commits into from
Nov 28, 2024

Conversation

sfzhu93
Copy link
Contributor

@sfzhu93 sfzhu93 commented Nov 26, 2024

This PR adds a command line argument --mlir-disable-diagnostic for disabling diagnostic information for mlir-opt.
When debugging with mlir-opt, some developers would like to disable the diagnostic information and focus specifically on the dumped IR. For example, triton-lang/triton#5250

Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot llvmbot added mlir:core MLIR Core Infrastructure mlir labels Nov 26, 2024
@llvmbot
Copy link
Member

llvmbot commented Nov 26, 2024

@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-mlir-core

Author: None (sfzhu93)

Changes

This PR adds a command line argument --mlir-disable-diagnostic for disabling diagnostic information for mlir-opt.
When debugging with mlir-opt, some developers would like to disable the diagnostic information and focus specifically on the dumped IR. For example, triton-lang/triton#5250


Full diff: https://github.com/llvm/llvm-project/pull/117669.diff

2 Files Affected:

  • (modified) mlir/include/mlir/Tools/mlir-opt/MlirOptMain.h (+7)
  • (modified) mlir/lib/Tools/mlir-opt/MlirOptMain.cpp (+7)
diff --git a/mlir/include/mlir/Tools/mlir-opt/MlirOptMain.h b/mlir/include/mlir/Tools/mlir-opt/MlirOptMain.h
index ef976c1155795b..026026ac3b78d0 100644
--- a/mlir/include/mlir/Tools/mlir-opt/MlirOptMain.h
+++ b/mlir/include/mlir/Tools/mlir-opt/MlirOptMain.h
@@ -82,6 +82,9 @@ class MlirOptMainConfig {
     return *this;
   }
   bool shouldEmitBytecode() const { return emitBytecodeFlag; }
+
+  bool shouldDisableDiagnostic() const { return disableDiagnosticFlag; }
+
   bool shouldElideResourceDataFromBytecode() const {
     return elideResourceDataFromBytecodeFlag;
   }
@@ -208,6 +211,10 @@ class MlirOptMainConfig {
   /// Emit bytecode instead of textual assembly when generating output.
   bool emitBytecodeFlag = false;
 
+  /// Disable the diagnostic handlers. Warnings, errors, remarks, etc. will not
+  /// be printed.
+  bool disableDiagnosticFlag = false;
+
   /// Elide resources when generating bytecode.
   bool elideResourceDataFromBytecodeFlag = false;
 
diff --git a/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp b/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp
index 5a7b17672c518b..c307e1d6abfb0d 100644
--- a/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp
+++ b/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp
@@ -113,6 +113,10 @@ struct MlirOptMainConfigCLOptions : public MlirOptMainConfig {
         cl::desc("Enable Debugger hook for debugging MLIR Actions"),
         cl::location(enableDebuggerActionHookFlag), cl::init(false));
 
+    static cl::opt<bool, /*ExternalStorage=*/true> disableRemarkDiagnostic(
+        "mlir-disable-diagnostic", cl::desc("Disable diagnostic information"),
+        cl::location(disableDiagnosticFlag), cl::init(false));
+
     static cl::opt<bool, /*ExternalStorage=*/true> explicitModule(
         "no-implicit-module",
         cl::desc("Disable implicit addition of a top-level module op during "
@@ -473,6 +477,9 @@ static LogicalResult processBuffer(raw_ostream &os,
   // If we are in verify diagnostics mode then we have a lot of work to do,
   // otherwise just perform the actions without worrying about it.
   if (!config.shouldVerifyDiagnostics()) {
+    if (config.shouldDisableDiagnostic())
+      return performActions(os, sourceMgr, &context, config);
+
     SourceMgrDiagnosticHandler sourceMgrHandler(*sourceMgr, &context);
     return performActions(os, sourceMgr, &context, config);
   }

@joker-eph
Copy link
Collaborator

If someone does not want to see diagnostics, why can't they just do 2>/dev/null?

@@ -113,6 +113,10 @@ struct MlirOptMainConfigCLOptions : public MlirOptMainConfig {
cl::desc("Enable Debugger hook for debugging MLIR Actions"),
cl::location(enableDebuggerActionHookFlag), cl::init(false));

static cl::opt<bool, /*ExternalStorage=*/true> disableRemarkDiagnostic(
"mlir-disable-diagnostic", cl::desc("Disable diagnostic information"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mehdi has a point: fully disabling diagnostics is not really a helpful flag. Plus, MLIR will still emit diagnostics even without a SourceMgrDiagnosticHandler. It might be better to change the flag to select a verbosity to suppress (1=remarks, 2=warnings, 3=everything) and then create a ScopedDiagnosticHandler that eats the diagnostics fitting that level.

Copy link
Contributor Author

@sfzhu93 sfzhu93 Nov 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated. My VSCode auto formats using an internal formatter when saving a file, and some unrelated formatting was included. Going to revert that later.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM after you fix formatting

Copy link

@jeffniu-openai jeffniu-openai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@sfzhu93
Copy link
Contributor Author

sfzhu93 commented Nov 28, 2024

Thank you all! Comments are resolved.

Copy link
Contributor

@Mogball Mogball left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Mogball Mogball merged commit 1f422dc into llvm:main Nov 28, 2024
7 checks passed
@Mogball
Copy link
Contributor

Mogball commented Nov 28, 2024

Thanks @sfzhu93 !

Copy link

@sfzhu93 Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mlir:core MLIR Core Infrastructure mlir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants