[Mlir-commits] [mlir] 3513267 - [mlir] Add op printing flag to skip regions (#77726)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Thu Jan 11 14:52:45 PST 2024


Author: Jakub Kuderski
Date: 2024-01-11T17:52:41-05:00
New Revision: 3513267770802b79fe5c020cf651942678b1e951

URL: https://github.com/llvm/llvm-project/commit/3513267770802b79fe5c020cf651942678b1e951
DIFF: https://github.com/llvm/llvm-project/commit/3513267770802b79fe5c020cf651942678b1e951.diff

LOG: [mlir] Add op printing flag to skip regions (#77726)

The new flag, `--mlir-print-skip-regions`, sets the op printing option
that disables region printing. This results in the usual
`--mlir-print-ir-*` debug options printing only the names of the
executed passes and the signatures of the ops.

Example:
```mlir
// -----// IR Dump Before CSE (cse) //----- //
func.func @bar(%arg0: f32, %arg1: f32) -> f32 {...}

// -----// IR Dump Before Canonicalizer (canonicalize) //----- //
func.func @bar(%arg0: f32, %arg1: f32) -> f32 {...}
```

The main use-case is to be triage compilation issues (crashes, slowness)
on very deep pass pipelines and with very large IR files, where printing
IR is prohibitively slow otherwise.

Added: 
    mlir/test/IR/print-skip-regions.mlir

Modified: 
    mlir/lib/IR/AsmPrinter.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/IR/AsmPrinter.cpp b/mlir/lib/IR/AsmPrinter.cpp
index 8fe8c78efecf9f..da417945b57fac 100644
--- a/mlir/lib/IR/AsmPrinter.cpp
+++ b/mlir/lib/IR/AsmPrinter.cpp
@@ -183,6 +183,10 @@ struct AsmPrinterOptions {
       llvm::cl::desc("Print with local scope and inline information (eliding "
                      "aliases for attributes, types, and locations")};
 
+  llvm::cl::opt<bool> skipRegionsOpt{
+      "mlir-print-skip-regions", llvm::cl::init(false),
+      llvm::cl::desc("Skip regions when printing ops.")};
+
   llvm::cl::opt<bool> printValueUsers{
       "mlir-print-value-users", llvm::cl::init(false),
       llvm::cl::desc(
@@ -217,6 +221,7 @@ OpPrintingFlags::OpPrintingFlags()
   printGenericOpFormFlag = clOptions->printGenericOpFormOpt;
   assumeVerifiedFlag = clOptions->assumeVerifiedOpt;
   printLocalScope = clOptions->printLocalScopeOpt;
+  skipRegionsFlag = clOptions->skipRegionsOpt;
   printValueUsersFlag = clOptions->printValueUsers;
 }
 

diff  --git a/mlir/test/IR/print-skip-regions.mlir b/mlir/test/IR/print-skip-regions.mlir
new file mode 100644
index 00000000000000..19a66e94f7f0b0
--- /dev/null
+++ b/mlir/test/IR/print-skip-regions.mlir
@@ -0,0 +1,18 @@
+// RUN: mlir-opt --no-implicit-module --mlir-print-skip-regions \
+// RUN:   --split-input-file %s | FileCheck %s
+
+// CHECK-LABEL: func.func @foo(%{{.+}}: i32, %{{.+}}: i32, %{{.+}}: i32) -> i32 {...}
+// CHECK-NOT:     return
+func.func @foo(%arg0: i32, %arg1: i32, %arg3: i32) -> i32 {
+  return %arg0: i32
+}
+
+// -----
+
+// CHECK: module {...}
+// CHECK-NOT: func.func
+module {
+  func.func @foo(%arg0: i32, %arg1: i32, %arg3: i32) -> i32 {
+    return %arg0: i32
+  }
+}


        


More information about the Mlir-commits mailing list