15#include "mlir/IR/BuiltinTypes.h"
16#include "mlir/IR/ImplicitLocOpBuilder.h"
26 StringRef reqName, Type reqType,
27 StringRef respName, Type respType) {
28 assert(reqType && respType);
29 auto *ctxt = reqType ? reqType.getContext() : respType.getContext();
30 auto bundle = ChannelBundleType::get(
32 {
BundledChannel{StringAttr::get(ctxt, reqName), ChannelDirection::from,
33 ChannelType::get(ctxt, reqType)},
34 BundledChannel{StringAttr::get(ctxt, respName), ChannelDirection::to,
35 ChannelType::get(ctxt, respType)}},
37 return {hw::InnerRefAttr::get(sym, StringAttr::get(ctxt, name)), bundle};
40void ChannelServiceDeclOp::getPortList(
41 SmallVectorImpl<ServicePortInfo> &ports) {
42 auto *ctxt = getContext();
44 hw::InnerRefAttr::get(getSymNameAttr(), StringAttr::get(ctxt,
"to_host")),
45 ChannelBundleType::get(
47 {
BundledChannel{StringAttr::get(ctxt,
"data"), ChannelDirection::from,
48 ChannelType::get(ctxt, AnyType::get(ctxt))}},
51 hw::InnerRefAttr::get(getSymNameAttr(),
52 StringAttr::get(ctxt,
"from_host")),
53 ChannelBundleType::get(
55 {
BundledChannel{StringAttr::get(ctxt,
"data"), ChannelDirection::to,
56 ChannelType::get(ctxt, AnyType::get(ctxt))}},
61 auto *ctxt = getContext();
63 IntegerType::get(ctxt, llvm::Log2_64_Ceil(getDepth()),
64 IntegerType::SignednessSemantics::Unsigned);
67 hw::StructType writeType = hw::StructType::get(
69 {hw::StructType::FieldInfo{StringAttr::get(ctxt,
"address"), addressType},
70 hw::StructType::FieldInfo{StringAttr::get(ctxt,
"data"),
72 return createReqResp(getSymNameAttr(),
"write",
"req", writeType,
"ack",
73 IntegerType::get(ctxt, 0));
77 auto *ctxt = getContext();
79 IntegerType::get(ctxt, llvm::Log2_64_Ceil(getDepth()),
80 IntegerType::SignednessSemantics::Unsigned);
82 return createReqResp(getSymNameAttr(),
"read",
"address", addressType,
"data",
86void RandomAccessMemoryDeclOp::getPortList(
87 SmallVectorImpl<ServicePortInfo> &ports) {
88 ports.push_back(writePortInfo());
89 ports.push_back(readPortInfo());
92void CallServiceDeclOp::getPortList(SmallVectorImpl<ServicePortInfo> &ports) {
93 auto *ctxt = getContext();
95 hw::InnerRefAttr::get(getSymNameAttr(), StringAttr::get(ctxt,
"call")),
96 ChannelBundleType::get(
98 {
BundledChannel{StringAttr::get(ctxt,
"arg"), ChannelDirection::from,
99 ChannelType::get(ctxt, AnyType::get(ctxt))},
100 BundledChannel{StringAttr::get(ctxt,
"result"), ChannelDirection::to,
101 ChannelType::get(ctxt, AnyType::get(ctxt))}},
105void FuncServiceDeclOp::getPortList(SmallVectorImpl<ServicePortInfo> &ports) {
106 auto *ctxt = getContext();
108 hw::InnerRefAttr::get(getSymNameAttr(), StringAttr::get(ctxt,
"call")),
109 ChannelBundleType::get(
111 {
BundledChannel{StringAttr::get(ctxt,
"arg"), ChannelDirection::to,
112 ChannelType::get(ctxt, AnyType::get(ctxt))},
114 ChannelDirection::from,
115 ChannelType::get(ctxt, AnyType::get(ctxt))}},
119void MMIOServiceDeclOp::getPortList(SmallVectorImpl<ServicePortInfo> &ports) {
120 auto *ctxt = getContext();
123 hw::InnerRefAttr::get(getSymNameAttr(), StringAttr::get(ctxt,
"read")),
124 ChannelBundleType::get(
127 StringAttr::get(ctxt,
"offset"), ChannelDirection::to,
131 ctxt, 32, IntegerType::SignednessSemantics::Unsigned))},
132 BundledChannel{StringAttr::get(ctxt,
"data"), ChannelDirection::from,
133 ChannelType::get(ctxt, IntegerType::get(ctxt, 64))}},
136 auto cmdType = hw::StructType::get(
138 hw::StructType::FieldInfo{StringAttr::get(ctxt,
"write"),
139 IntegerType::get(ctxt, 1)},
140 hw::StructType::FieldInfo{
141 StringAttr::get(ctxt,
"offset"),
143 ctxt, 32, IntegerType::SignednessSemantics::Unsigned)},
144 hw::StructType::FieldInfo{StringAttr::get(ctxt,
"data"),
145 IntegerType::get(ctxt, 64)},
148 hw::InnerRefAttr::get(getSymNameAttr(),
149 StringAttr::get(ctxt,
"read_write")),
150 ChannelBundleType::get(
152 {
BundledChannel{StringAttr::get(ctxt,
"cmd"), ChannelDirection::to,
153 ChannelType::get(ctxt, cmdType)},
154 BundledChannel{StringAttr::get(ctxt,
"data"), ChannelDirection::from,
155 ChannelType::get(ctxt, IntegerType::get(ctxt, 64))}},
160 auto *ctxt = getContext();
168 getSymNameAttr(),
"write",
"req", AnyType::get(ctxt),
"ackTag",
169 IntegerType::get(ctxt, 8, IntegerType::SignednessSemantics::Unsigned));
173 auto *ctxt = getContext();
175 IntegerType::get(ctxt, 64, IntegerType::SignednessSemantics::Unsigned);
179 hw::StructType readReqType = hw::StructType::get(
181 hw::StructType::FieldInfo{StringAttr::get(ctxt,
"address"),
183 hw::StructType::FieldInfo{
184 StringAttr::get(ctxt,
"tag"),
186 ctxt, 8, IntegerType::SignednessSemantics::Unsigned)},
188 hw::StructType readRespType = hw::StructType::get(
190 hw::StructType::FieldInfo{
191 StringAttr::get(ctxt,
"tag"),
193 ctxt, 8, IntegerType::SignednessSemantics::Unsigned)},
194 hw::StructType::FieldInfo{StringAttr::get(ctxt,
"data"),
197 return createReqResp(getSymNameAttr(),
"read",
"req", readReqType,
"resp",
202 auto *ctxt = getContext();
204 IntegerType::get(ctxt, 64, IntegerType::SignednessSemantics::Unsigned);
206 IntegerType::get(ctxt, 8, IntegerType::SignednessSemantics::Unsigned);
217 hw::StructType readReqType = hw::StructType::get(
218 ctxt, {hw::StructType::FieldInfo{StringAttr::get(ctxt,
"address"), ui64},
219 hw::StructType::FieldInfo{StringAttr::get(ctxt,
"tag"), ui8},
220 hw::StructType::FieldInfo{StringAttr::get(ctxt,
"length"),
221 AnyType::get(ctxt)}});
222 return createReqResp(getSymNameAttr(),
"read_list",
"req", readReqType,
223 "resp", AnyType::get(ctxt));
226void HostMemServiceDeclOp::getPortList(
227 SmallVectorImpl<ServicePortInfo> &ports) {
228 ports.push_back(writePortInfo());
229 ports.push_back(readPortInfo());
230 ports.push_back(readListPortInfo());
233LogicalResult HostMemServiceDeclOp::verifyRequest(
const ServicePortInfo &port,
234 ChannelBundleType reqType,
240 if (port.
port.getName().getValue() !=
"read_list")
244 if (ch.name.getValue() !=
"req")
246 auto structType = dyn_cast<hw::StructType>(ch.type.getInner());
249 Type lengthType = structType.getFieldType(
"length");
252 if (
auto intType = dyn_cast<IntegerType>(lengthType);
253 intType && intType.isUnsigned())
255 return reqOp->emitOpError()
256 <<
"'read_list' request 'length' must be an unsigned integer, got "
262void TelemetryServiceDeclOp::getPortList(
263 SmallVectorImpl<ServicePortInfo> &ports) {
264 auto *ctxt = getContext();
266 hw::InnerRefAttr::get(getSymNameAttr(), StringAttr::get(ctxt,
"report")),
267 ChannelBundleType::get(
269 {
BundledChannel{StringAttr::get(ctxt,
"get"), ChannelDirection::to,
270 ChannelType::get(ctxt, IntegerType::get(ctxt, 0))},
271 BundledChannel{StringAttr::get(ctxt,
"data"), ChannelDirection::from,
272 ChannelType::get(ctxt, AnyType::get(ctxt))}},
assert(baseType &&"element must be base type")
static ServicePortInfo createReqResp(StringAttr sym, Twine name, StringRef reqName, Type reqType, StringRef respName, Type respType)
Utility function to create a req/resp pair bundle service port.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Describes a service port.