CIRCT  19.0.0git
ReductionUtils.cpp
Go to the documentation of this file.
1 //===- ReductionUtils.cpp - Reduction pattern utilities -------------------===//
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 
10 #include "circt/Reduce/Reduction.h"
11 #include "mlir/IR/Operation.h"
12 #include "llvm/ADT/SmallSet.h"
13 
14 using namespace circt;
15 
16 void reduce::pruneUnusedOps(Operation *initialOp, Reduction &reduction) {
17  SmallVector<Operation *> worklist;
19  worklist.push_back(initialOp);
20  while (!worklist.empty()) {
21  auto *op = worklist.pop_back_val();
22  if (!op->use_empty())
23  continue;
24  for (auto arg : op->getOperands())
25  if (auto *argOp = arg.getDefiningOp())
26  if (handled.insert(argOp).second)
27  worklist.push_back(argOp);
28  reduction.notifyOpErased(op);
29  op->erase();
30  }
31 }
void pruneUnusedOps(Operation *initialOp, Reduction &reduction)
Starting at the given op, traverse through it and its operands and erase operations that have no more...
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition: DebugAnalysis.h:21
An abstract reduction pattern.
Definition: Reduction.h:24
void notifyOpErased(Operation *op)
Definition: Reduction.h:77