CIRCT 23.0.0git
Loading...
Searching...
No Matches
ESIStdServices.cpp
Go to the documentation of this file.
1//===- ESIStdServices.cpp - ESI standard services -------------------------===//
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
14
15#include "mlir/IR/BuiltinTypes.h"
16#include "mlir/IR/ImplicitLocOpBuilder.h"
17
18#include <map>
19#include <memory>
20
21using namespace circt;
22using namespace circt::esi;
23
24/// Utility function to create a req/resp pair bundle service port.
25static ServicePortInfo createReqResp(StringAttr sym, Twine name,
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(
31 ctxt,
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)}},
36 /*resettable=false*/ UnitAttr());
37 return {hw::InnerRefAttr::get(sym, StringAttr::get(ctxt, name)), bundle};
38}
39
40void ChannelServiceDeclOp::getPortList(
41 SmallVectorImpl<ServicePortInfo> &ports) {
42 auto *ctxt = getContext();
43 ports.push_back(ServicePortInfo{
44 hw::InnerRefAttr::get(getSymNameAttr(), StringAttr::get(ctxt, "to_host")),
45 ChannelBundleType::get(
46 ctxt,
47 {BundledChannel{StringAttr::get(ctxt, "data"), ChannelDirection::from,
48 ChannelType::get(ctxt, AnyType::get(ctxt))}},
49 /*resettable=*/UnitAttr())});
50 ports.push_back(ServicePortInfo{
51 hw::InnerRefAttr::get(getSymNameAttr(),
52 StringAttr::get(ctxt, "from_host")),
53 ChannelBundleType::get(
54 ctxt,
55 {BundledChannel{StringAttr::get(ctxt, "data"), ChannelDirection::to,
56 ChannelType::get(ctxt, AnyType::get(ctxt))}},
57 /*resettable=*/UnitAttr())});
58}
59
60ServicePortInfo RandomAccessMemoryDeclOp::writePortInfo() {
61 auto *ctxt = getContext();
62 auto addressType =
63 IntegerType::get(ctxt, llvm::Log2_64_Ceil(getDepth()),
64 IntegerType::SignednessSemantics::Unsigned);
65
66 // Write port
67 hw::StructType writeType = hw::StructType::get(
68 ctxt,
69 {hw::StructType::FieldInfo{StringAttr::get(ctxt, "address"), addressType},
70 hw::StructType::FieldInfo{StringAttr::get(ctxt, "data"),
71 getInnerType()}});
72 return createReqResp(getSymNameAttr(), "write", "req", writeType, "ack",
73 IntegerType::get(ctxt, 0));
74}
75
76ServicePortInfo RandomAccessMemoryDeclOp::readPortInfo() {
77 auto *ctxt = getContext();
78 auto addressType =
79 IntegerType::get(ctxt, llvm::Log2_64_Ceil(getDepth()),
80 IntegerType::SignednessSemantics::Unsigned);
81
82 return createReqResp(getSymNameAttr(), "read", "address", addressType, "data",
83 getInnerType());
84}
85
86void RandomAccessMemoryDeclOp::getPortList(
87 SmallVectorImpl<ServicePortInfo> &ports) {
88 ports.push_back(writePortInfo());
89 ports.push_back(readPortInfo());
90}
91
92void CallServiceDeclOp::getPortList(SmallVectorImpl<ServicePortInfo> &ports) {
93 auto *ctxt = getContext();
94 ports.push_back(ServicePortInfo{
95 hw::InnerRefAttr::get(getSymNameAttr(), StringAttr::get(ctxt, "call")),
96 ChannelBundleType::get(
97 ctxt,
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))}},
102 /*resettable=*/UnitAttr())});
103}
104
105void FuncServiceDeclOp::getPortList(SmallVectorImpl<ServicePortInfo> &ports) {
106 auto *ctxt = getContext();
107 ports.push_back(ServicePortInfo{
108 hw::InnerRefAttr::get(getSymNameAttr(), StringAttr::get(ctxt, "call")),
109 ChannelBundleType::get(
110 ctxt,
111 {BundledChannel{StringAttr::get(ctxt, "arg"), ChannelDirection::to,
112 ChannelType::get(ctxt, AnyType::get(ctxt))},
113 BundledChannel{StringAttr::get(ctxt, "result"),
114 ChannelDirection::from,
115 ChannelType::get(ctxt, AnyType::get(ctxt))}},
116 /*resettable=*/UnitAttr())});
117}
118
119void MMIOServiceDeclOp::getPortList(SmallVectorImpl<ServicePortInfo> &ports) {
120 auto *ctxt = getContext();
121 // Read only port.
122 ports.push_back(ServicePortInfo{
123 hw::InnerRefAttr::get(getSymNameAttr(), StringAttr::get(ctxt, "read")),
124 ChannelBundleType::get(
125 ctxt,
127 StringAttr::get(ctxt, "offset"), ChannelDirection::to,
128 ChannelType::get(
129 ctxt,
130 IntegerType::get(
131 ctxt, 32, IntegerType::SignednessSemantics::Unsigned))},
132 BundledChannel{StringAttr::get(ctxt, "data"), ChannelDirection::from,
133 ChannelType::get(ctxt, IntegerType::get(ctxt, 64))}},
134 /*resettable=*/UnitAttr())});
135 // Read-write port.
136 auto cmdType = hw::StructType::get(
137 ctxt, {
138 hw::StructType::FieldInfo{StringAttr::get(ctxt, "write"),
139 IntegerType::get(ctxt, 1)},
140 hw::StructType::FieldInfo{
141 StringAttr::get(ctxt, "offset"),
142 IntegerType::get(
143 ctxt, 32, IntegerType::SignednessSemantics::Unsigned)},
144 hw::StructType::FieldInfo{StringAttr::get(ctxt, "data"),
145 IntegerType::get(ctxt, 64)},
146 });
147 ports.push_back(ServicePortInfo{
148 hw::InnerRefAttr::get(getSymNameAttr(),
149 StringAttr::get(ctxt, "read_write")),
150 ChannelBundleType::get(
151 ctxt,
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))}},
156 /*resettable=*/UnitAttr())});
157}
158
159ServicePortInfo HostMemServiceDeclOp::writePortInfo() {
160 auto *ctxt = getContext();
161 auto addressType =
162 IntegerType::get(ctxt, 64, IntegerType::SignednessSemantics::Unsigned);
163
164 // Write port
165 hw::StructType writeType = hw::StructType::get(
166 ctxt,
167 {hw::StructType::FieldInfo{StringAttr::get(ctxt, "address"), addressType},
168 hw::StructType::FieldInfo{
169 StringAttr::get(ctxt, "tag"),
170 IntegerType::get(ctxt, 8,
171 IntegerType::SignednessSemantics::Unsigned)},
172 hw::StructType::FieldInfo{StringAttr::get(ctxt, "data"),
173 AnyType::get(ctxt)}});
174 return createReqResp(
175 getSymNameAttr(), "write", "req", writeType, "ackTag",
176 IntegerType::get(ctxt, 8, IntegerType::SignednessSemantics::Unsigned));
177}
178
179ServicePortInfo HostMemServiceDeclOp::readPortInfo() {
180 auto *ctxt = getContext();
181 auto addressType =
182 IntegerType::get(ctxt, 64, IntegerType::SignednessSemantics::Unsigned);
183
184 hw::StructType readReqType = hw::StructType::get(
185 ctxt, {
186 hw::StructType::FieldInfo{StringAttr::get(ctxt, "address"),
187 addressType},
188 hw::StructType::FieldInfo{
189 StringAttr::get(ctxt, "tag"),
190 IntegerType::get(
191 ctxt, 8, IntegerType::SignednessSemantics::Unsigned)},
192 });
193 hw::StructType readRespType = hw::StructType::get(
194 ctxt, {
195 hw::StructType::FieldInfo{
196 StringAttr::get(ctxt, "tag"),
197 IntegerType::get(
198 ctxt, 8, IntegerType::SignednessSemantics::Unsigned)},
199 hw::StructType::FieldInfo{StringAttr::get(ctxt, "data"),
200 AnyType::get(ctxt)},
201 });
202 return createReqResp(getSymNameAttr(), "read", "req", readReqType, "resp",
203 readRespType);
204}
205
206void HostMemServiceDeclOp::getPortList(
207 SmallVectorImpl<ServicePortInfo> &ports) {
208 ports.push_back(writePortInfo());
209 ports.push_back(readPortInfo());
210}
211
212void TelemetryServiceDeclOp::getPortList(
213 SmallVectorImpl<ServicePortInfo> &ports) {
214 auto *ctxt = getContext();
215 ports.push_back(ServicePortInfo{
216 hw::InnerRefAttr::get(getSymNameAttr(), StringAttr::get(ctxt, "report")),
217 ChannelBundleType::get(
218 ctxt,
219 {BundledChannel{StringAttr::get(ctxt, "get"), ChannelDirection::to,
220 ChannelType::get(ctxt, IntegerType::get(ctxt, 0))},
221 BundledChannel{StringAttr::get(ctxt, "data"), ChannelDirection::from,
222 ChannelType::get(ctxt, AnyType::get(ctxt))}},
223 /*resettable=*/UnitAttr())});
224}
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.
Definition ESIOps.h:31