CIRCT 23.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 utility class that generates metasyntactic variable names for use in
26/// reductions. This provides a consistent naming scheme across different
27/// reduction patterns.
29public:
31
32 /// Get the next metasyntactic name in the sequence.
33 const char *getNextName();
34
35 /// Reset the generator to start from the beginning of the sequence.
36 void reset() { index = 0; }
37
38private:
39 size_t index = 0;
40 constexpr static const char *names[48] = {
41 "Foo", "Bar", "Baz", "Qux", "Quux", "Quuux", "Quuuux",
42 "Quz", "Corge", "Grault", "Bazola", "Ztesch", "Thud", "Grunt",
43 "Bletch", "Fum", "Fred", "Jim", "Sheila", "Barney", "Flarp",
44 "Zxc", "Spqr", "Wombat", "Shme", "Bongo", "Spam", "Eggs",
45 "Snork", "Zot", "Blarg", "Wibble", "Toto", "Titi", "Tata",
46 "Tutu", "Pippo", "Pluto", "Paperino", "Aap", "Noot", "Mies",
47 "Oogle", "Foogle", "Boogle", "Zork", "Gork", "Bork"};
48};
49
50/// A helper struct that scans a root operation and all its nested operations
51/// for `InnerRefAttr`s.
53 InnerSymbolUses(Operation *root);
54
55 InnerSymbolUses() = default;
56 InnerSymbolUses(const InnerSymbolUses &) = default;
58
61
62 /// Check whether an op is targeted by an inner ref. Considers both the
63 /// `sym_name` and the `inner_sym` attributes on the given op.
64 bool hasInnerRef(Operation *op) const;
65 /// Check if the given inner ref is used.
66 bool hasInnerRef(hw::InnerRefAttr innerRef) const;
67 /// Check if the given symbol name is targeted by an inner ref.
68 bool hasInnerRef(StringAttr symbol) const;
69 /// Check if the given symbol and inner symbol name pair is targeted by an
70 /// inner ref.
71 bool hasInnerRef(StringAttr symbol, StringAttr innerSym) const;
72
73 /// Check whether the given symbol is targeted by a symbol ref.
74 bool hasSymbolRef(Operation *op) const;
75 /// Check whether the given symbol name is targeted by a symbol ref.
76 bool hasSymbolRef(StringAttr symbol) const;
77
78 /// Check whether the given symbol is targeted by a symbol ref or inner ref.
79 bool hasRef(Operation *op) const;
80 /// Check whether the given symbol name is targeted by a symbol ref or inner
81 /// ref.
82 bool hasRef(StringAttr symbol) const;
83
84private:
85 /// Symbol and inner symbol name pairs used in inner refs.
86 DenseSet<std::pair<StringAttr, StringAttr>> innerRefs;
87 /// Symbol names used in inner refs.
88 DenseSet<StringAttr> innerRefModules;
89 /// Symbol names used in symbol or inner refs.
90 DenseSet<StringAttr> symbolRefs;
91};
92
93} // namespace reduce
94} // namespace circt
95
96#endif // CIRCT_REDUCE_REDUCTIONUTILS_H
A utility class that generates metasyntactic variable names for use in reductions.
void reset()
Reset the generator to start from the beginning of the sequence.
const char * getNextName()
Get the next metasyntactic name in the sequence.
static constexpr const char * names[48]
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.