[Mlir-commits] [mlir] bdb955b - [MLIR] Add `print-ir` pass for debugging purposes

Frederik Gossen llvmlistbot at llvm.org
Wed Mar 1 11:42:23 PST 2023


Author: Frederik Gossen
Date: 2023-03-01T14:42:10-05:00
New Revision: bdb955b307c56f42290a6f88409673093841c3ab

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

LOG: [MLIR] Add `print-ir` pass for debugging purposes

Add pass to print the entire IR on the debug stream.
This is meant for debugging purposes to inspect the IR at a specific point in the pipeline.

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

Added: 
    mlir/lib/Transforms/PrintIR.cpp

Modified: 
    mlir/include/mlir/Transforms/Passes.h
    mlir/include/mlir/Transforms/Passes.td
    mlir/lib/Transforms/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Transforms/Passes.h b/mlir/include/mlir/Transforms/Passes.h
index 2ff8a4c71bb7..12986c9bd1ff 100644
--- a/mlir/include/mlir/Transforms/Passes.h
+++ b/mlir/include/mlir/Transforms/Passes.h
@@ -64,6 +64,9 @@ std::unique_ptr<Pass> createControlFlowSinkPass();
 /// Creates a pass to perform common sub expression elimination.
 std::unique_ptr<Pass> createCSEPass();
 
+/// Creates a pass to print IR on the debug stream.
+std::unique_ptr<Pass> createPrintIRPass();
+
 /// Creates a pass that generates IR to verify ops at runtime.
 std::unique_ptr<Pass> createGenerateRuntimeVerificationPass();
 

diff  --git a/mlir/include/mlir/Transforms/Passes.td b/mlir/include/mlir/Transforms/Passes.td
index 9f159ba35ff7..d667ceaa37f4 100644
--- a/mlir/include/mlir/Transforms/Passes.td
+++ b/mlir/include/mlir/Transforms/Passes.td
@@ -85,6 +85,15 @@ def CSE : Pass<"cse"> {
   ];
 }
 
+def PrintIRPass : Pass<"print-ir"> {
+  let summary = "Print IR on the debug stream";
+  let description = [{
+    Print the entire IR on the debug stream. This is meant for debugging
+    purposes to inspect the IR at a specific point in the pipeline.
+  }];
+  let constructor = "mlir::createPrintIRPass()";
+}
+
 def GenerateRuntimeVerification : Pass<"generate-runtime-verification"> {
   let summary = "Generate additional runtime op verification checks";
   let description = [{

diff  --git a/mlir/lib/Transforms/CMakeLists.txt b/mlir/lib/Transforms/CMakeLists.txt
index 3a6b06467c11..4929a20847a7 100644
--- a/mlir/lib/Transforms/CMakeLists.txt
+++ b/mlir/lib/Transforms/CMakeLists.txt
@@ -9,6 +9,7 @@ add_mlir_library(MLIRTransforms
   LocationSnapshot.cpp
   LoopInvariantCodeMotion.cpp
   OpStats.cpp
+  PrintIR.cpp
   SCCP.cpp
   StripDebugInfo.cpp
   SymbolDCE.cpp

diff  --git a/mlir/lib/Transforms/PrintIR.cpp b/mlir/lib/Transforms/PrintIR.cpp
new file mode 100644
index 000000000000..41cb6efd29fc
--- /dev/null
+++ b/mlir/lib/Transforms/PrintIR.cpp
@@ -0,0 +1,29 @@
+//===- PrintIR.cpp - Pass to dump IR on debug stream ----------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "mlir/Pass/Pass.h"
+
+namespace mlir {
+namespace {
+
+#define GEN_PASS_DEF_PRINTIRPASS
+#include "mlir/Transforms/Passes.h.inc"
+
+struct PrintIRPass : public impl::PrintIRPassBase<PrintIRPass> {
+  PrintIRPass() = default;
+
+  void runOnOperation() override { getOperation()->dump(); }
+};
+
+} // namespace
+
+std::unique_ptr<Pass> createPrintIRPass() {
+  return std::make_unique<PrintIRPass>();
+}
+
+} // namespace mlir
\ No newline at end of file


        


More information about the Mlir-commits mailing list