Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9be49b9

Browse files
committed
[Handshake] Buffering properties improvements
This commit slightly changes the methods of the ChannelBufProps struct, removing those that do not appear to be immediately useful and, on the contrary, adding immediately useful ones.
1 parent 9e579d9 commit 9be49b9

File tree

2 files changed

+32
-41
lines changed

2 files changed

+32
-41
lines changed

include/circt/Dialect/Handshake/HandshakeOps.h

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -86,25 +86,12 @@ struct ChannelBufProps {
8686
unsigned minOpaque = 0,
8787
std::optional<unsigned> maxOpaque = std::nullopt);
8888

89-
/// Produces channel buffering properties based on the current ones minus a
90-
/// particular number of transparent slots. Returns std::nullopt if the
91-
/// provided number of slots is greater than the maximum number of allowed
92-
/// slots (indicating that properties can't be satisfied).
93-
std::optional<ChannelBufProps> subtractTrans(unsigned numSlots);
94-
95-
/// Produces channel buffering properties based on the current ones minus a
96-
/// particular number of opaque slots. Returns std::nullopt if the
97-
/// provided number of slots is greater than the maximum number of allowed
98-
/// slots (indicating that properties can't be satisfied).
99-
std::optional<ChannelBufProps> subtractOpaque(unsigned numSlots);
89+
/// Determines whether these buffering properties are satisfiable i.e.,
90+
/// whether it's possible to create a buffer that respects them.
91+
bool isSatisfiable() const;
10092

10193
/// Computes member-wise equality.
102-
inline bool operator==(const ChannelBufProps &rhs) const {
103-
return (this->minTrans == rhs.minTrans) &&
104-
(this->maxTrans == rhs.maxTrans) &&
105-
(this->minOpaque == rhs.minOpaque) &&
106-
(this->maxOpaque == rhs.maxOpaque);
107-
}
94+
bool operator==(const ChannelBufProps &rhs) const;
10895
};
10996

11097
/// Custom specialization of llvm::hash_value for ChannelBufProps. Converts the
@@ -114,6 +101,12 @@ struct ChannelBufProps {
114101
llvm::hash_code hash_value(const ChannelBufProps &props);
115102
} // namespace dynamatic
116103

104+
/// Prints the buffering properties as two closed or semi-open intervals
105+
/// (depending on whether maximum are defined), one for tranparent slots and one
106+
/// for opaque slots.
107+
std::ostream &operator<<(std::ostream &os,
108+
const dynamatic::ChannelBufProps &props);
109+
117110
namespace mlir {
118111
namespace OpTrait {
119112
template <typename ConcreteType>

lib/Dialect/Handshake/HandshakeOps.cpp

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1895,30 +1895,28 @@ ChannelBufProps::ChannelBufProps(unsigned minTrans,
18951895
: minTrans(minTrans), maxTrans(maxTrans), minOpaque(minOpaque),
18961896
maxOpaque(maxOpaque){};
18971897

1898-
std::optional<ChannelBufProps>
1899-
ChannelBufProps::subtractTrans(unsigned numSlots) {
1900-
std::optional<unsigned> newMaxTrans;
1901-
if (maxTrans.has_value()) {
1902-
if (maxTrans.value() < numSlots)
1903-
return {};
1904-
newMaxTrans = maxTrans.value() - numSlots;
1905-
}
1906-
1907-
unsigned newMinTrans = minTrans < numSlots ? 0U : minTrans - numSlots;
1908-
return ChannelBufProps(newMinTrans, minTrans, minOpaque, maxOpaque);
1909-
}
1910-
1911-
std::optional<ChannelBufProps>
1912-
ChannelBufProps::subtractOpaque(unsigned numSlots) {
1913-
std::optional<unsigned> newMaxOpaque;
1914-
if (maxOpaque.has_value()) {
1915-
if (maxOpaque.value() < numSlots)
1916-
return {};
1917-
newMaxOpaque = maxOpaque.value() - numSlots;
1918-
}
1919-
1920-
unsigned newMinOpaque = minOpaque < numSlots ? 0U : minOpaque - numSlots;
1921-
return ChannelBufProps(minTrans, maxTrans, newMinOpaque, newMaxOpaque);
1898+
bool ChannelBufProps::isSatisfiable() const {
1899+
return (!maxTrans.has_value() || maxTrans.value() > minTrans) &&
1900+
(!maxOpaque.has_value() || maxOpaque.value() > minOpaque);
1901+
}
1902+
1903+
bool ChannelBufProps::operator==(const ChannelBufProps &rhs) const {
1904+
return (this->minTrans == rhs.minTrans) && (this->maxTrans == rhs.maxTrans) &&
1905+
(this->minOpaque == rhs.minOpaque) &&
1906+
(this->maxOpaque == rhs.maxOpaque);
1907+
}
1908+
1909+
std::ostream &operator<<(std::ostream &os, const ChannelBufProps &props) {
1910+
std::string maxTransStr = props.maxTrans.has_value()
1911+
? (std::to_string(props.maxTrans.value()) + "]")
1912+
: "inf)";
1913+
std::string maxOpaqueStr =
1914+
props.maxOpaque.has_value()
1915+
? (std::to_string(props.maxOpaque.value()) + "]")
1916+
: "inf)";
1917+
os << "T: [" << props.minTrans << ", " << maxTransStr << ", O: ["
1918+
<< props.minOpaque << ", " << maxOpaqueStr;
1919+
return os;
19221920
}
19231921

19241922
llvm::hash_code dynamatic::hash_value(const ChannelBufProps &props) {

0 commit comments

Comments
 (0)