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 dump the IR on debug stream. +std::unique_ptr createDumpIRPass(); + /// 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 DumpIRPass : Pass<"dump-ir"> { + let summary = "Dump IR on debug stream"; + let description = [{ + Dump 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::createDumpIRPass()"; +} + 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 @@ -4,6 +4,7 @@ Canonicalizer.cpp ControlFlowSink.cpp CSE.cpp + DumpIRPass.cpp GenerateRuntimeVerification.cpp Inliner.cpp LocationSnapshot.cpp diff --git a/mlir/lib/Transforms/DumpIR.cpp b/mlir/lib/Transforms/DumpIR.cpp new file mode 100644 --- /dev/null +++ b/mlir/lib/Transforms/DumpIR.cpp @@ -0,0 +1,29 @@ +//===- DumpIR.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_DUMPIRPASS +#include "mlir/Transforms/Passes.h.inc" + +struct DumpIRPass : public impl::DumpIRPassBase { + DumpIRPass() = default; + + void runOnOperation() override { getOperation()->dump(); } +}; + +} // namespace + +std::unique_ptr createDumpIRPass() { + return std::make_unique(); +} + +} // namespace mlir \ No newline at end of file