49 : ImplicitLocOpBuilder(UnknownLoc::get(top->getContext()), top),
50 a(StringAttr::get(getContext(),
"a")),
51 aValid(StringAttr::get(getContext(),
"a_valid")),
52 aReady(StringAttr::get(getContext(),
"a_ready")),
53 x(StringAttr::get(getContext(),
"x")),
54 xValid(StringAttr::get(getContext(),
"x_valid")),
55 xReady(StringAttr::get(getContext(),
"x_ready")),
56 dataOutValid(StringAttr::get(getContext(),
"DataOutValid")),
57 dataOutReady(StringAttr::get(getContext(),
"DataOutReady")),
58 dataOut(StringAttr::get(getContext(),
"DataOut")),
59 dataInValid(StringAttr::get(getContext(),
"DataInValid")),
60 dataInReady(StringAttr::get(getContext(),
"DataInReady")),
61 dataIn(StringAttr::get(getContext(),
"DataIn")),
62 clk(StringAttr::get(getContext(),
"clk")),
63 rst(StringAttr::get(getContext(),
"rst")),
64 width(StringAttr::get(getContext(),
"WIDTH")) {
66 auto regions = top->getRegions();
67 if (regions.empty()) {
68 top->emitError(
"ESI HW Builder needs a region to insert HW.");
70 auto ®ion = regions.front();
72 setInsertionPoint(®ion.front(), region.front().begin());
76 StringRef proposedNameRef) {
77 SmallString<64> proposedName = proposedNameRef;
80 for (
char &ch : proposedName) {
88 size_t baseLength = proposedName.size();
90 while (SymbolTable::lookupSymbolIn(tableOp, proposedName)) {
91 proposedName.resize(baseLength);
92 proposedName.append(llvm::utostr(++tries));
95 return StringAttr::get(tableOp->getContext(), proposedName);
100 getInsertionPoint()->getParentWithTrait<mlir::OpTrait::SymbolTable>();
103 std::string portTypeName;
104 llvm::raw_string_ostream nameOS(portTypeName);
105 TypeSwitch<Type>(port.getInner())
106 .Case([&](hw::ArrayType arr) {
107 nameOS <<
"ArrayOf" << arr.getNumElements() <<
'x'
108 << arr.getElementType();
110 .Case([&](hw::StructType t) { nameOS <<
"Struct"; })
111 .Default([&](Type t) { nameOS << port.getInner(); });
114 ssize_t i = portTypeName.size() - 1;
115 while (i >= 0 && portTypeName[i] ==
'_') {
118 portTypeName = portTypeName.substr(0, i + 1);
121 SmallString<64> proposedName(
"IValidReady_");
122 proposedName.append(portTypeName);
138 PipelineStageOp stage) {
139 Type dataType = stage.innerType();
150 llvm::SmallVector<PortInfo> ports = {
152 {{
rst, getI1Type(), ModulePort::Direction::Input}, argn++}};
154 ports.push_back({{
a, dataType, ModulePort::Direction::Input}, argn++});
156 {{
aValid, getI1Type(), ModulePort::Direction::Input}, argn++});
158 {{
aReady, getI1Type(), ModulePort::Direction::Output}, resn++});
159 ports.push_back({{
x, dataType, ModulePort::Direction::Output}, resn++});
162 {{
xValid, getI1Type(), ModulePort::Direction::Output}, resn++});
164 {{
xReady, getI1Type(), ModulePort::Direction::Input}, argn++});
166 stageMod = create<HWModuleExternOp>(
180 SmallVector<Attribute, 8> params;
182 ParamDeclAttr::get(
"ENDPOINT_ID", NoneType::get(getContext())));
184 ParamDeclAttr::get(
"TO_HOST_TYPE_ID", NoneType::get(getContext())));
185 params.push_back(ParamDeclAttr::get(
"TO_HOST_SIZE_BITS", getI32Type()));
187 auto dataInType = hw::IntType::get(hw::ParamDeclRefAttr::get(
188 StringAttr::get(getContext(),
"TO_HOST_SIZE_BITS"),
189 getIntegerType(32,
false)));
192 {{
rst, getI1Type(), ModulePort::Direction::Input}, 1},
193 {{
dataInValid, getI1Type(), ModulePort::Direction::Input}, 2},
194 {{
dataInReady, getI1Type(), ModulePort::Direction::Output}, 3},
195 {{
dataIn, dataInType, ModulePort::Direction::Input}, 4}};
199 "Cosim_Endpoint_ToHost", ArrayAttr::get(getContext(), params));
208 SmallVector<Attribute, 8> params;
210 ParamDeclAttr::get(
"ENDPOINT_ID", NoneType::get(getContext())));
212 ParamDeclAttr::get(
"FROM_HOST_TYPE_ID", NoneType::get(getContext())));
213 params.push_back(ParamDeclAttr::get(
"FROM_HOST_SIZE_BITS", getI32Type()));
215 auto dataInType = hw::IntType::get(hw::ParamDeclRefAttr::get(
216 StringAttr::get(getContext(),
"FROM_HOST_SIZE_BITS"),
217 getIntegerType(32,
false)));
220 {{
rst, getI1Type(), ModulePort::Direction::Input}, 1},
221 {{
dataOutValid, getI1Type(), ModulePort::Direction::Output}, 2},
222 {{
dataOutReady, getI1Type(), ModulePort::Direction::Input}, 3},
223 {{
dataOut, dataInType, ModulePort::Direction::Output}, 4}};
227 "Cosim_Endpoint_FromHost", ArrayAttr::get(getContext(), params));
245 create<InterfaceSignalOp>(
validStr, getI1Type());
246 create<InterfaceSignalOp>(
readyStr, getI1Type());
247 create<InterfaceSignalOp>(
dataStr, chan.getInner());
248 llvm::SmallVector<StringRef> validDataStrs;
250 validDataStrs.push_back(
dataStr);
251 create<InterfaceModportOp>(
sinkStr,