[flang] Fix crash in HLFIR generation (#118399)
[llvm-project.git] / mlir / lib / Transforms / PrintIR.cpp
blob439e55da0293fb2e3604eda835d581a4b019575c
1 //===- PrintIR.cpp - Pass to dump IR on debug stream ----------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "mlir/Pass/Pass.h"
10 #include "mlir/Transforms/Passes.h"
11 #include "llvm/Support/Debug.h"
13 namespace mlir {
14 namespace {
16 #define GEN_PASS_DEF_PRINTIRPASS
17 #include "mlir/Transforms/Passes.h.inc"
19 struct PrintIRPass : public impl::PrintIRPassBase<PrintIRPass> {
20 using impl::PrintIRPassBase<PrintIRPass>::PrintIRPassBase;
22 void runOnOperation() override {
23 llvm::dbgs() << "// -----// IR Dump";
24 if (!this->label.empty())
25 llvm::dbgs() << " " << this->label;
26 llvm::dbgs() << " //----- //\n";
27 getOperation()->dump();
28 markAllAnalysesPreserved();
32 } // namespace
34 std::unique_ptr<Pass> createPrintIRPass(const PrintIRPassOptions &options) {
35 return std::make_unique<PrintIRPass>(options);
38 } // namespace mlir