MLIR 23.0.0git
TrivialDeadCodeElimination.cpp
Go to the documentation of this file.
1//===- TrivialDeadCodeElimination.cpp - Trivial DCE -----------------------===//
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 "mlir/IR/Operation.h"
10#include "mlir/Pass/Pass.h"
13
14namespace mlir {
15#define GEN_PASS_DEF_TRIVIALDEADCODEELIMINATIONPASS
16#include "mlir/Transforms/Passes.h.inc"
17} // namespace mlir
18
19using namespace mlir;
20
21namespace {
22struct TrivialDeadCodeElimination
24 TrivialDeadCodeElimination> {
25 using impl::TrivialDeadCodeEliminationPassBase<
26 TrivialDeadCodeElimination>::TrivialDeadCodeEliminationPassBase;
27
28 void runOnOperation() override {
29 Operation *target = getOperation();
30 IRRewriter rewriter(target->getContext());
31 if (removeBlocks)
32 (void)eraseUnreachableBlocks(rewriter, target->getRegions(), recursive);
33 for (Region &region : target->getRegions())
34 eliminateTriviallyDeadOps(rewriter, region, recursive);
35 }
36};
37} // namespace
Include the generated interface declarations.
LogicalResult eraseUnreachableBlocks(RewriterBase &rewriter, MutableArrayRef< Region > regions, bool recurse=true)
Erase the unreachable blocks within the provided regions.
bool eliminateTriviallyDeadOps(RewriterBase &rewriter, Region &region, bool includeNestedRegions=true)
Remove trivially dead operations from region.