CIRCT  20.0.0git
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 
13 #include "circt/Dialect/HW/HWOps.h"
14 
15 #include "mlir/IR/BuiltinTypes.h"
16 #include "mlir/IR/ImplicitLocOpBuilder.h"
17 
18 #include <map>
19 #include <memory>
20 
21 using namespace circt;
22 using namespace circt::esi;
23 
24 /// Utility function to create a req/resp pair bundle service port.
25 static 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 
40 ServicePortInfo 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",
52 }
53 
54 ServicePortInfo 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 
63  SmallVectorImpl<ServicePortInfo> &ports) {
64  ports.push_back(writePortInfo());
65  ports.push_back(readPortInfo());
66 }
67 
68 void CallServiceDeclOp::getPortList(SmallVectorImpl<ServicePortInfo> &ports) {
69  auto *ctxt = getContext();
70  ports.push_back(ServicePortInfo{
71  hw::InnerRefAttr::get(getSymNameAttr(), StringAttr::get(ctxt, "call")),
73  ctxt,
74  {BundledChannel{StringAttr::get(ctxt, "arg"), ChannelDirection::from,
76  BundledChannel{StringAttr::get(ctxt, "result"), ChannelDirection::to,
78  /*resettable=*/UnitAttr())});
79 }
80 
81 void FuncServiceDeclOp::getPortList(SmallVectorImpl<ServicePortInfo> &ports) {
82  auto *ctxt = getContext();
83  ports.push_back(ServicePortInfo{
84  hw::InnerRefAttr::get(getSymNameAttr(), StringAttr::get(ctxt, "call")),
86  ctxt,
87  {BundledChannel{StringAttr::get(ctxt, "arg"), ChannelDirection::to,
90  ChannelDirection::from,
92  /*resettable=*/UnitAttr())});
93 }
94 
95 void 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")),
101  ctxt,
103  StringAttr::get(ctxt, "offset"), ChannelDirection::to,
105  ctxt,
107  ctxt, 32, IntegerType::SignednessSemantics::Unsigned))},
108  BundledChannel{StringAttr::get(ctxt, "data"), ChannelDirection::from,
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"),
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")),
127  ctxt,
128  {BundledChannel{StringAttr::get(ctxt, "cmd"), ChannelDirection::to,
129  ChannelType::get(ctxt, cmdType)},
130  BundledChannel{StringAttr::get(ctxt, "data"), ChannelDirection::from,
132  /*resettable=*/UnitAttr())});
133 }
134 
135 ServicePortInfo 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"),
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 
155 ServicePortInfo 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"),
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"),
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 
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.
static SmallVector< PortInfo > getPortList(ModuleTy &mod)
Definition: HWOps.cpp:1420
Direction get(bool isOutput)
Returns an output direction if isOutput is true, otherwise returns an input direction.
Definition: CalyxOps.cpp:55
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition: DebugAnalysis.h:21
Describes a service port.
Definition: ESIOps.h:31