14#define GEN_PASS_DEF_DUPLICATEFUNCTIONELIMINATIONPASS
15#include "mlir/Dialect/Func/Transforms/Passes.h.inc"
22struct DuplicateFuncOpEquivalenceInfo
25 static unsigned getHashValue(
const func::FuncOp cFunc) {
32 func::FuncOp
func =
const_cast<func::FuncOp &
>(cFunc);
33 StringAttr symNameAttrName =
func.getSymNameAttrName();
35 StringAttr attrName = namedAttr.getName();
36 if (attrName == symNameAttrName)
38 hash = llvm::hash_combine(
hash, namedAttr);
43 hash = llvm::hash_combine(
53 static bool isEqual(func::FuncOp
lhs, func::FuncOp
rhs) {
56 if (
lhs.isDeclaration() ||
rhs.isDeclaration())
60 if (
lhs->getDiscardableAttrDictionary() !=
61 rhs->getDiscardableAttrDictionary())
67 auto pLhs =
lhs.getProperties();
68 auto pRhs =
rhs.getProperties();
69 pLhs.sym_name =
nullptr;
70 pRhs.sym_name =
nullptr;
80struct DuplicateFunctionEliminationPass
82 DuplicateFunctionEliminationPass> {
84 using DuplicateFunctionEliminationPassBase<
85 DuplicateFunctionEliminationPass>::DuplicateFunctionEliminationPassBase;
87 void runOnOperation()
override {
88 auto module = getOperation();
94 module.walk([&](func::FuncOp f) {
95 auto [repr, inserted] = uniqueFuncOps.insert(f);
96 getRepresentant[f.getSymNameAttr()] = *repr;
106 for (
auto it : toBeErased) {
107 StringAttr oldSymbol = it.getSymNameAttr();
108 StringAttr newSymbol = getRepresentant[oldSymbol].getSymNameAttr();
static size_t hash(const T &value)
Local helper to compute std::hash for a value.
*if copies could not be generated due to yet unimplemented cases *copyInPlacementStart and copyOutPlacementStart in copyPlacementBlock *specify the insertion points where the incoming copies and outgoing should be inserted(the insertion happens right before the *insertion point). Since `begin` can itself be invalidated due to the memref *rewriting done from this method
NamedAttribute represents a combination of a name and an Attribute value.
Operation is the basic unit of execution within MLIR.
This class represents a collection of SymbolTables.
This class represents a map of symbols to users, and provides efficient implementations of symbol que...
void replaceAllUsesWith(Operation *symbol, StringAttr newSymbolName)
Replace all of the uses of the given symbol with newSymbolName.
Include the generated interface declarations.
llvm::DenseMapInfo< T, Enable > DenseMapInfo
llvm::DenseSet< ValueT, ValueInfoT > DenseSet
llvm::DenseMap< KeyT, ValueT, KeyInfoT, BucketT > DenseMap
static llvm::hash_code ignoreHashValue(Value)
Helper that can be used with computeHash above to ignore operation operands/result mapping.
static bool isRegionEquivalentTo(Region *lhs, Region *rhs, function_ref< LogicalResult(Value, Value)> checkEquivalent, function_ref< void(Value, Value)> markEquivalent, OperationEquivalence::Flags flags, function_ref< LogicalResult(ValueRange, ValueRange)> checkCommutativeEquivalent=nullptr)
Compare two regions (including their subregions) and return if they are equivalent.
static llvm::hash_code computeHash(Operation *op, function_ref< llvm::hash_code(Value)> hashOperands=[](Value v) { return hash_value(v);}, function_ref< llvm::hash_code(Value)> hashResults=[](Value v) { return hash_value(v);}, Flags flags=Flags::None)
Compute a hash for the given operation.