[Instrumentation] Fix a warning
[llvm-project.git] / flang / lib / Optimizer / Transforms / SimplifyRegionLite.cpp
blob7d1f86f8cee9443939af194bffcf3a8a87428293
1 //===- SimplifyRegionLite.cpp -- region simplification lite ---------------===//
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 "flang/Optimizer/Dialect/FIROps.h"
10 #include "flang/Optimizer/Transforms/Passes.h"
11 #include "mlir/IR/PatternMatch.h"
12 #include "mlir/Pass/Pass.h"
13 #include "mlir/Transforms/DialectConversion.h"
14 #include "mlir/Transforms/GreedyPatternRewriteDriver.h"
15 #include "mlir/Transforms/RegionUtils.h"
17 namespace fir {
18 #define GEN_PASS_DEF_SIMPLIFYREGIONLITE
19 #include "flang/Optimizer/Transforms/Passes.h.inc"
20 } // namespace fir
22 namespace {
24 class SimplifyRegionLitePass
25 : public fir::impl::SimplifyRegionLiteBase<SimplifyRegionLitePass> {
26 public:
27 void runOnOperation() override;
30 class DummyRewriter : public mlir::PatternRewriter {
31 public:
32 DummyRewriter(mlir::MLIRContext *ctx) : mlir::PatternRewriter(ctx) {}
35 } // namespace
37 void SimplifyRegionLitePass::runOnOperation() {
38 auto op = getOperation();
39 auto regions = op->getRegions();
40 mlir::RewritePatternSet patterns(op.getContext());
41 DummyRewriter rewriter(op.getContext());
42 if (regions.empty())
43 return;
45 (void)mlir::eraseUnreachableBlocks(rewriter, regions);
46 (void)mlir::runRegionDCE(rewriter, regions);