12#include "mlir/IR/Operation.h"
13#include "llvm/ADT/SmallSet.h"
34 static const llvm::StringSet<> nameSet = [] {
41 return nameSet.contains(name.split(
'_').first);
51 while (!worklist.empty()) {
52 auto *op = worklist.pop_back_val();
53 if (!op || handled.contains(op) || !op->use_empty() ||
54 op->hasAttr(
"inner_sym"))
57 for (
auto arg : op->getOperands())
58 if (
auto *argOp = arg.getDefiningOp())
59 worklist.push_back(argOp);
66 SmallVector<Operation *> worklist({initialOp});
75 return op->getAttrOfType<StringAttr>(SymbolTable::getSymbolAttrName());
79 root->walk([&](Operation *op) {
80 auto collect = [&](Attribute attr) {
81 if (
auto symbolRef = dyn_cast<FlatSymbolRefAttr>(attr))
84 if (
auto innerRef = dyn_cast<hw::InnerRefAttr>(attr)) {
85 innerRefs.insert({innerRef.getModule(), innerRef.getName()});
89 for (
auto namedAttr : op->getAttrs())
90 namedAttr.getValue().walk(collect);
91 for (
auto result : op->getResults())
92 result.getType().walk(collect);
93 for (
auto ®ion : op->getRegions())
94 for (
auto &block : region)
95 for (
auto arg : block.getArguments())
96 arg.getType().walk(collect);
106 auto *parent = op->getParentOp();
108 parent = parent->getParentOp();
117 return innerRefs.contains({innerRef.getModule(), innerRef.getName()});
125 StringAttr innerSym)
const {
126 return innerRefs.contains({symbol, innerSym});
static StringAttr getSymbolName(Operation *op)
A namespace that is used to store existing names and generate new names in some scope within the IR.
StringRef newName(const Twine &name)
Return a unique name, derived from the input name, and add the new name to the internal namespace.
static StringAttr getInnerSymbol(Operation *op)
Get InnerSymbol for an operation.
void pruneUnusedOps(SmallVectorImpl< Operation * > &worklist, Reduction &reduction)
Starting from an initial worklist of operations, traverse through it and its operands and erase opera...
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
An abstract reduction pattern.
void notifyOpErased(Operation *op)
DenseSet< StringAttr > innerRefModules
Symbol names used in inner refs.
bool hasSymbolRef(Operation *op) const
Check whether the given symbol is targeted by a symbol ref.
bool hasInnerRef(Operation *op) const
Check whether an op is targeted by an inner ref.
DenseSet< StringAttr > symbolRefs
Symbol names used in symbol or inner refs.
InnerSymbolUses()=default
bool hasRef(Operation *op) const
Check whether the given symbol is targeted by a symbol ref or inner ref.
DenseSet< std::pair< StringAttr, StringAttr > > innerRefs
Symbol and inner symbol name pairs used in inner refs.