[Mlir-commits] [mlir] 047c7aa - Improve diagnostic when emitting operations with regions

Uday Bondhugula llvmlistbot at llvm.org
Thu Sep 8 01:18:23 PDT 2022


Author: Uday Bondhugula
Date: 2022-09-08T13:47:48+05:30
New Revision: 047c7aa96dadf8a2c71a29e2df610d628d9e7e3e

URL: https://github.com/llvm/llvm-project/commit/047c7aa96dadf8a2c71a29e2df610d628d9e7e3e
DIFF: https://github.com/llvm/llvm-project/commit/047c7aa96dadf8a2c71a29e2df610d628d9e7e3e.diff

LOG: Improve diagnostic when emitting operations with regions

This has a broad impact on diagnostics that attach an operation. Ops
with one or more regions will now be printed on a new line. It was
confusing and hard to read with a trailing first line for ops
with regions.

Before:

```
<unknown>:0: note: see current operation: affine.for %arg3 = 0 to 8192 {
  affine.for %arg4 = 0 to 8192 step 512 {
    affine.for %arg5 = 0 to 8192 step 128 {

    ...
```

After:

```
<unknown>:0: note: see current operation:
affine.for %arg3 = 0 to 8192 {
  affine.for %arg4 = 0 to 8192 step 512 {
    affine.for %arg5 = 0 to 8192 step 128 {
      ...
```

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

Added: 
    

Modified: 
    mlir/include/mlir/IR/Diagnostics.h
    mlir/lib/IR/Diagnostics.cpp
    mlir/test/IR/print-op-on-diagnostic.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/IR/Diagnostics.h b/mlir/include/mlir/IR/Diagnostics.h
index 1123adc814364..9748072dafff8 100644
--- a/mlir/include/mlir/IR/Diagnostics.h
+++ b/mlir/include/mlir/IR/Diagnostics.h
@@ -197,10 +197,10 @@ class Diagnostic {
   Diagnostic &operator<<(OperationName val);
 
   /// Stream in an Operation.
-  Diagnostic &operator<<(Operation &val);
-  Diagnostic &operator<<(Operation *val) { return *this << *val; }
+  Diagnostic &operator<<(Operation &op);
+  Diagnostic &operator<<(Operation *op) { return *this << *op; }
   /// Append an operation with the given printing flags.
-  Diagnostic &appendOp(Operation &val, const OpPrintingFlags &flags);
+  Diagnostic &appendOp(Operation &op, const OpPrintingFlags &flags);
 
   /// Stream in a Value.
   Diagnostic &operator<<(Value val);

diff  --git a/mlir/lib/IR/Diagnostics.cpp b/mlir/lib/IR/Diagnostics.cpp
index 83bc50bfec974..6d6f2b7c93b59 100644
--- a/mlir/lib/IR/Diagnostics.cpp
+++ b/mlir/lib/IR/Diagnostics.cpp
@@ -133,13 +133,18 @@ static OpPrintingFlags adjustPrintingFlags(OpPrintingFlags flags,
 }
 
 /// Stream in an Operation.
-Diagnostic &Diagnostic::operator<<(Operation &val) {
-  return appendOp(val, OpPrintingFlags());
+Diagnostic &Diagnostic::operator<<(Operation &op) {
+  return appendOp(op, OpPrintingFlags());
 }
-Diagnostic &Diagnostic::appendOp(Operation &val, const OpPrintingFlags &flags) {
+
+Diagnostic &Diagnostic::appendOp(Operation &op, const OpPrintingFlags &flags) {
   std::string str;
   llvm::raw_string_ostream os(str);
-  val.print(os, adjustPrintingFlags(flags, severity));
+  op.print(os, adjustPrintingFlags(flags, severity));
+  // Print on a new line for better readability if the op will be printed on
+  // multiple lines.
+  if (str.find('\n') != std::string::npos)
+    *this << '\n';
   return *this << os.str();
 }
 

diff  --git a/mlir/test/IR/print-op-on-diagnostic.mlir b/mlir/test/IR/print-op-on-diagnostic.mlir
index 39add1d9ecb3c..9c81420545237 100644
--- a/mlir/test/IR/print-op-on-diagnostic.mlir
+++ b/mlir/test/IR/print-op-on-diagnostic.mlir
@@ -1,7 +1,18 @@
-// RUN: not mlir-opt %s -mlir-print-op-on-diagnostic 2>&1 | FileCheck %s
+// RUN: not mlir-opt -split-input-file %s -mlir-print-op-on-diagnostic 2>&1 | FileCheck %s
 
 // This file tests the functionality of 'mlir-print-op-on-diagnostic'.
 
 // CHECK: {{invalid to use 'test.invalid_attr'}}
-// CHECK: {{see current operation: "builtin.module"()}}
+// CHECK: see current operation:
+// CHECK-NEXT: "builtin.module"()
 module attributes {test.invalid_attr} {}
+
+// -----
+
+func.func @foo() {
+  "test.foo"(%cst) : (index) -> ()
+  // CHECK: {{operand #0 does not dominate this use}}
+  // CHECK: {{see current operation: "test.foo"(.*)}}
+  %cst = arith.constant 0 : index
+  return
+}


        


More information about the Mlir-commits mailing list