Skip to content

Commit

Permalink
[MLIR] Add print-ir pass for debugging purposes
Browse files Browse the repository at this point in the history
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
  • Loading branch information
frgossen committed Mar 1, 2023
1 parent ff761f2 commit bdb955b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
3 changes: 3 additions & 0 deletions mlir/include/mlir/Transforms/Passes.h
Expand Up @@ -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();

Expand Down
9 changes: 9 additions & 0 deletions mlir/include/mlir/Transforms/Passes.td
Expand Up @@ -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 = [{
Expand Down
1 change: 1 addition & 0 deletions mlir/lib/Transforms/CMakeLists.txt
Expand Up @@ -9,6 +9,7 @@ add_mlir_library(MLIRTransforms
LocationSnapshot.cpp
LoopInvariantCodeMotion.cpp
OpStats.cpp
PrintIR.cpp
SCCP.cpp
StripDebugInfo.cpp
SymbolDCE.cpp
Expand Down
29 changes: 29 additions & 0 deletions 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

0 comments on commit bdb955b

Please sign in to comment.