CIRCT 22.0.0git
Loading...
Searching...
No Matches
ReductionUtils.h
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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#ifndef CIRCT_REDUCE_REDUCTIONUTILS_H
10#define CIRCT_REDUCE_REDUCTIONUTILS_H
11
13#include "circt/Support/LLVM.h"
14
15namespace circt {
16// Forward declarations.
17struct Reduction;
18
19namespace reduce {
20
21/// Starting at the given `op`, traverse through it and its operands and erase
22/// operations that have no more uses.
23void pruneUnusedOps(Operation *initialOp, Reduction &reduction);
24
25/// A helper struct that scans a root operation and all its nested operations
26/// for `InnerRefAttr`s.
28 InnerSymbolUses(Operation *root);
29
30 InnerSymbolUses() = default;
31 InnerSymbolUses(const InnerSymbolUses &) = default;
33
36
37 /// Check whether an op is targeted by an inner ref. Considers both the
38 /// `sym_name` and the `inner_sym` attributes on the given op.
39 bool hasInnerRef(Operation *op) const;
40 /// Check if the given inner ref is used.
41 bool hasInnerRef(hw::InnerRefAttr innerRef) const;
42 /// Check if the given symbol name is targeted by an inner ref.
43 bool hasInnerRef(StringAttr symbol) const;
44 /// Check if the given symbol and inner symbol name pair is targeted by an
45 /// inner ref.
46 bool hasInnerRef(StringAttr symbol, StringAttr innerSym) const;
47
48 /// Check whether the given symbol is targeted by a symbol ref.
49 bool hasSymbolRef(Operation *op) const;
50 /// Check whether the given symbol name is targeted by a symbol ref.
51 bool hasSymbolRef(StringAttr symbol) const;
52
53 /// Check whether the given symbol is targeted by a symbol ref or inner ref.
54 bool hasRef(Operation *op) const;
55 /// Check whether the given symbol name is targeted by a symbol ref or inner
56 /// ref.
57 bool hasRef(StringAttr symbol) const;
58
59private:
60 /// Symbol and inner symbol name pairs used in inner refs.
61 DenseSet<std::pair<StringAttr, StringAttr>> innerRefs;
62 /// Symbol names used in inner refs.
63 DenseSet<StringAttr> innerRefModules;
64 /// Symbol names used in symbol or inner refs.
65 DenseSet<StringAttr> symbolRefs;
66};
67
68} // namespace reduce
69} // namespace circt
70
71#endif // CIRCT_REDUCE_REDUCTIONUTILS_H
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.
An abstract reduction pattern.
Definition Reduction.h:24
A helper struct that scans a root operation and all its nested operations for InnerRefAttrs.
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 & operator=(InnerSymbolUses &&)=default
bool hasRef(Operation *op) const
Check whether the given symbol is targeted by a symbol ref or inner ref.
InnerSymbolUses & operator=(const InnerSymbolUses &)=default
InnerSymbolUses(const InnerSymbolUses &)=default
InnerSymbolUses(InnerSymbolUses &&)=default
DenseSet< std::pair< StringAttr, StringAttr > > innerRefs
Symbol and inner symbol name pairs used in inner refs.