diff --git a/mlir/include/mlir/Transforms/Passes.h b/mlir/include/mlir/Transforms/Passes.h --- a/mlir/include/mlir/Transforms/Passes.h +++ b/mlir/include/mlir/Transforms/Passes.h @@ -64,6 +64,9 @@ /// Creates a pass to perform common sub expression elimination. std::unique_ptr createCSEPass(); +/// Creates a pass to print IR on the debug stream. +std::unique_ptr createPrintIRPass(); + /// Creates a pass that generates IR to verify ops at runtime. std::unique_ptr createGenerateRuntimeVerificationPass(); diff --git a/mlir/include/mlir/Transforms/Passes.td b/mlir/include/mlir/Transforms/Passes.td --- a/mlir/include/mlir/Transforms/Passes.td +++ b/mlir/include/mlir/Transforms/Passes.td @@ -85,6 +85,15 @@ ]; } +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 --- a/mlir/lib/Transforms/CMakeLists.txt +++ b/mlir/lib/Transforms/CMakeLists.txt @@ -9,6 +9,7 @@ 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 --- /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() = default; + + void runOnOperation() override { getOperation()->dump(); } +}; + +} // namespace + +std::unique_ptr createPrintIRPass() { + return std::make_unique(); +} + +} // namespace mlir \ No newline at end of file