CIRCT  19.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 FuncServiceDeclOp::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::to,
77  ChannelDirection::from,
79  /*resettable=*/UnitAttr())});
80 }
81 
82 void MMIOServiceDeclOp::getPortList(SmallVectorImpl<ServicePortInfo> &ports) {
83  auto *ctxt = getContext();
84  // Read only port.
85  ports.push_back(ServicePortInfo{
86  hw::InnerRefAttr::get(getSymNameAttr(), StringAttr::get(ctxt, "read")),
88  ctxt,
89  {BundledChannel{StringAttr::get(ctxt, "offset"), ChannelDirection::to,
91  BundledChannel{StringAttr::get(ctxt, "data"), ChannelDirection::from,
93  /*resettable=*/UnitAttr())});
94  // Write only port.
95  ports.push_back(ServicePortInfo{
96  hw::InnerRefAttr::get(getSymNameAttr(), StringAttr::get(ctxt, "write")),
98  ctxt,
99  {BundledChannel{StringAttr::get(ctxt, "offset"), ChannelDirection::to,
101  BundledChannel{StringAttr::get(ctxt, "data"), ChannelDirection::to,
103  /*resettable=*/UnitAttr())});
104 }
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:1414
Direction get(bool isOutput)
Returns an output direction if isOutput is true, otherwise returns an input direction.
Definition: CalyxOps.cpp:54
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition: DebugAnalysis.h:21
Describes a service port.
Definition: ESIOps.h:31