CIRCT 20.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
40ServicePortInfo RandomAccessMemoryDeclOp::writePortInfo() {
41 auto *ctxt = getContext();
42 auto addressType = IntegerType::get(ctxt, llvm::Log2_64_Ceil(getDepth()));
43
44 // Write port
45 hw::StructType writeType = hw::StructType::get(
46 ctxt,
47 {hw::StructType::FieldInfo{StringAttr::get(ctxt, "address"), addressType},
48 hw::StructType::FieldInfo{StringAttr::get(ctxt, "data"),
49 getInnerType()}});
50 return createReqResp(getSymNameAttr(), "write", "req", writeType, "ack",
51 IntegerType::get(ctxt, 0));
52}
53
54ServicePortInfo RandomAccessMemoryDeclOp::readPortInfo() {
55 auto *ctxt = getContext();
56 auto addressType = IntegerType::get(ctxt, llvm::Log2_64_Ceil(getDepth()));
57
58 return createReqResp(getSymNameAttr(), "read", "address", addressType, "data",
59 getInnerType());
60}
61
62void RandomAccessMemoryDeclOp::getPortList(
63 SmallVectorImpl<ServicePortInfo> &ports) {
64 ports.push_back(writePortInfo());
65 ports.push_back(readPortInfo());
66}
67
68void CallServiceDeclOp::getPortList(SmallVectorImpl<ServicePortInfo> &ports) {
69 auto *ctxt = getContext();
70 ports.push_back(ServicePortInfo{
71 hw::InnerRefAttr::get(getSymNameAttr(), StringAttr::get(ctxt, "call")),
72 ChannelBundleType::get(
73 ctxt,
74 {BundledChannel{StringAttr::get(ctxt, "arg"), ChannelDirection::from,
75 ChannelType::get(ctxt, AnyType::get(ctxt))},
76 BundledChannel{StringAttr::get(ctxt, "result"), ChannelDirection::to,
77 ChannelType::get(ctxt, AnyType::get(ctxt))}},
78 /*resettable=*/UnitAttr())});
79}
80
81void FuncServiceDeclOp::getPortList(SmallVectorImpl<ServicePortInfo> &ports) {
82 auto *ctxt = getContext();
83 ports.push_back(ServicePortInfo{
84 hw::InnerRefAttr::get(getSymNameAttr(), StringAttr::get(ctxt, "call")),
85 ChannelBundleType::get(
86 ctxt,
87 {BundledChannel{StringAttr::get(ctxt, "arg"), ChannelDirection::to,
88 ChannelType::get(ctxt, AnyType::get(ctxt))},
89 BundledChannel{StringAttr::get(ctxt, "result"),
90 ChannelDirection::from,
91 ChannelType::get(ctxt, AnyType::get(ctxt))}},
92 /*resettable=*/UnitAttr())});
93}
94
95void MMIOServiceDeclOp::getPortList(SmallVectorImpl<ServicePortInfo> &ports) {
96 auto *ctxt = getContext();
97 // Read only port.
98 ports.push_back(ServicePortInfo{
99 hw::InnerRefAttr::get(getSymNameAttr(), StringAttr::get(ctxt, "read")),
100 ChannelBundleType::get(
101 ctxt,
103 StringAttr::get(ctxt, "offset"), ChannelDirection::to,
104 ChannelType::get(
105 ctxt,
106 IntegerType::get(
107 ctxt, 32, IntegerType::SignednessSemantics::Unsigned))},
108 BundledChannel{StringAttr::get(ctxt, "data"), ChannelDirection::from,
109 ChannelType::get(ctxt, IntegerType::get(ctxt, 64))}},
110 /*resettable=*/UnitAttr())});
111 // Read-write port.
112 auto cmdType = hw::StructType::get(
113 ctxt, {
114 hw::StructType::FieldInfo{StringAttr::get(ctxt, "write"),
115 IntegerType::get(ctxt, 1)},
116 hw::StructType::FieldInfo{
117 StringAttr::get(ctxt, "offset"),
118 IntegerType::get(
119 ctxt, 32, IntegerType::SignednessSemantics::Unsigned)},
120 hw::StructType::FieldInfo{StringAttr::get(ctxt, "data"),
121 IntegerType::get(ctxt, 64)},
122 });
123 ports.push_back(ServicePortInfo{
124 hw::InnerRefAttr::get(getSymNameAttr(),
125 StringAttr::get(ctxt, "read_write")),
126 ChannelBundleType::get(
127 ctxt,
128 {BundledChannel{StringAttr::get(ctxt, "cmd"), ChannelDirection::to,
129 ChannelType::get(ctxt, cmdType)},
130 BundledChannel{StringAttr::get(ctxt, "data"), ChannelDirection::from,
131 ChannelType::get(ctxt, IntegerType::get(ctxt, 64))}},
132 /*resettable=*/UnitAttr())});
133}
134
135ServicePortInfo HostMemServiceDeclOp::writePortInfo() {
136 auto *ctxt = getContext();
137 auto addressType =
138 IntegerType::get(ctxt, 64, IntegerType::SignednessSemantics::Unsigned);
139
140 // Write port
141 hw::StructType writeType = hw::StructType::get(
142 ctxt,
143 {hw::StructType::FieldInfo{StringAttr::get(ctxt, "address"), addressType},
144 hw::StructType::FieldInfo{
145 StringAttr::get(ctxt, "tag"),
146 IntegerType::get(ctxt, 8,
147 IntegerType::SignednessSemantics::Unsigned)},
148 hw::StructType::FieldInfo{StringAttr::get(ctxt, "data"),
149 AnyType::get(ctxt)}});
150 return createReqResp(
151 getSymNameAttr(), "write", "req", writeType, "ackTag",
152 IntegerType::get(ctxt, 8, IntegerType::SignednessSemantics::Unsigned));
153}
154
155ServicePortInfo HostMemServiceDeclOp::readPortInfo() {
156 auto *ctxt = getContext();
157 auto addressType =
158 IntegerType::get(ctxt, 64, IntegerType::SignednessSemantics::Unsigned);
159
160 hw::StructType readReqType = hw::StructType::get(
161 ctxt, {
162 hw::StructType::FieldInfo{StringAttr::get(ctxt, "address"),
163 addressType},
164 hw::StructType::FieldInfo{
165 StringAttr::get(ctxt, "tag"),
166 IntegerType::get(
167 ctxt, 8, IntegerType::SignednessSemantics::Unsigned)},
168 });
169 hw::StructType readRespType = hw::StructType::get(
170 ctxt, {
171 hw::StructType::FieldInfo{
172 StringAttr::get(ctxt, "tag"),
173 IntegerType::get(
174 ctxt, 8, IntegerType::SignednessSemantics::Unsigned)},
175 hw::StructType::FieldInfo{StringAttr::get(ctxt, "data"),
176 AnyType::get(ctxt)},
177 });
178 return createReqResp(getSymNameAttr(), "read", "req", readReqType, "resp",
179 readRespType);
180}
181
182void HostMemServiceDeclOp::getPortList(
183 SmallVectorImpl<ServicePortInfo> &ports) {
184 ports.push_back(writePortInfo());
185 ports.push_back(readPortInfo());
186}
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