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//===----------------------------------------------------------------------===//
8
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"
16
17namespace fir {
18#define GEN_PASS_DEF_SIMPLIFYREGIONLITE
19#include "flang/Optimizer/Transforms/Passes.h.inc"
20} // namespace fir
21
22namespace {
23
24class SimplifyRegionLitePass
25 : public fir::impl::SimplifyRegionLiteBase<SimplifyRegionLitePass> {
26public:
27 void runOnOperation() override;
28};
29
30class DummyRewriter : public mlir::PatternRewriter {
31public:
32 DummyRewriter(mlir::MLIRContext *ctx) : mlir::PatternRewriter(ctx) {}
33};
34
35} // namespace
36
37void 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;
44
45 (void)mlir::eraseUnreachableBlocks(rewriter, regions);
46 (void)mlir::runRegionDCE(rewriter, regions);
47}
48
49std::unique_ptr<mlir::Pass> fir::createSimplifyRegionLitePass() {
50 return std::make_unique<SimplifyRegionLitePass>();
51}
52

source code of flang/lib/Optimizer/Transforms/SimplifyRegionLite.cpp