1 //===- SimplifyRegionLite.cpp -- region simplification lite ---------------===//
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
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"
18 #define GEN_PASS_DEF_SIMPLIFYREGIONLITE
19 #include "flang/Optimizer/Transforms/Passes.h.inc"
24 class SimplifyRegionLitePass
25 : public fir::impl::SimplifyRegionLiteBase
<SimplifyRegionLitePass
> {
27 void runOnOperation() override
;
30 class DummyRewriter
: public mlir::PatternRewriter
{
32 DummyRewriter(mlir::MLIRContext
*ctx
) : mlir::PatternRewriter(ctx
) {}
37 void SimplifyRegionLitePass::runOnOperation() {
38 auto op
= getOperation();
39 auto regions
= op
->getRegions();
40 mlir::RewritePatternSet
patterns(op
.getContext());
41 DummyRewriter
rewriter(op
.getContext());
45 (void)mlir::eraseUnreachableBlocks(rewriter
, regions
);
46 (void)mlir::runRegionDCE(rewriter
, regions
);
49 std::unique_ptr
<mlir::Pass
> fir::createSimplifyRegionLitePass() {
50 return std::make_unique
<SimplifyRegionLitePass
>();