11#include "mlir/IR/Builders.h"
12#include "mlir/IR/DialectImplementation.h"
13#include "llvm/ADT/TypeSwitch.h"
14#include "llvm/Support/MathExtras.h"
20#define GET_TYPEDEF_CLASSES
21#include "circt/Dialect/AXI4/AXI4Types.cpp.inc"
23LogicalResult PortType::verify(function_ref<InFlightDiagnostic()> emitError,
24 uint32_t addr_width, uint32_t data_width,
25 uint32_t write_id_width, uint32_t read_id_width,
26 uint32_t user_width, WindowSetAttr windows,
27 uint32_t outstanding_writes,
28 uint32_t outstanding_reads) {
30 return emitError() <<
"port 'addr_width' must be at most 64, got "
32 if (data_width < 8 || data_width > 1024 || !llvm::isPowerOf2_32(data_width))
33 return emitError() <<
"port 'data_width' must be a power of two between 8 "
36 if (write_id_width > 32)
37 return emitError() <<
"port 'write_id_width' must be at most 32, got "
39 if (read_id_width > 32)
40 return emitError() <<
"port 'read_id_width' must be at most 32, got "
43 if (outstanding_writes > (uint64_t{1} << write_id_width))
44 return emitError() <<
"port 'outstanding_writes' must be at most "
45 << (uint64_t{1} << write_id_width)
46 <<
" for a 'write_id_width' of " << write_id_width
47 <<
", got " << outstanding_writes;
48 if (outstanding_reads > (uint64_t{1} << read_id_width))
49 return emitError() <<
"port 'outstanding_reads' must be at most "
50 << (uint64_t{1} << read_id_width)
51 <<
" for a 'read_id_width' of " << read_id_width
52 <<
", got " << outstanding_reads;
57 MLIRContext *ctx = port.getContext();
58 auto field = [&](StringRef name,
unsigned width) {
59 return hw::StructType::FieldInfo{StringAttr::get(ctx, name),
60 IntegerType::get(ctx, width)};
63 auto addressFields = [&](
unsigned idWidth) {
64 return SmallVector<hw::StructType::FieldInfo>{
66 field(
"addr", port.getAddrWidth()),
75 field(
"user", port.getUserWidth())};
78 SmallVector<hw::StructType::FieldInfo> fields;
81 fields = addressFields(port.getWriteIdWidth());
84 fields = addressFields(port.getReadIdWidth());
87 fields = {field(
"data", port.getDataWidth()),
88 field(
"strb", port.getDataWidth() / 8), field(
"last",
kLastWidth),
89 field(
"user", port.getUserWidth())};
92 fields = {field(
"id", port.getWriteIdWidth()), field(
"resp",
kRespWidth),
93 field(
"user", port.getUserWidth())};
96 fields = {field(
"id", port.getReadIdWidth()),
97 field(
"data", port.getDataWidth()), field(
"resp",
kRespWidth),
98 field(
"last",
kLastWidth), field(
"user", port.getUserWidth())};
101 return hw::StructType::get(ctx, fields);
104void AXI4Dialect::registerTypes() {
106#define GET_TYPEDEF_LIST
107#include "circt/Dialect/AXI4/AXI4Types.cpp.inc"
constexpr unsigned kRespWidth
constexpr unsigned kProtWidth
constexpr unsigned kLastWidth
constexpr unsigned kQosWidth
hw::StructType getChannelPayloadType(PortType port, AXI4Channel channel)
Build the hw.struct payload type for one channel of an !axi4.port.
constexpr unsigned kRegionWidth
AXI4Channel
The five AXI4 channels.
constexpr unsigned kBurstWidth
constexpr unsigned kLenWidth
constexpr unsigned kSizeWidth
constexpr unsigned kCacheWidth
constexpr unsigned kLockWidth
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.