17 #include "mlir/IR/BuiltinAttributes.h"
18 #include "mlir/IR/BuiltinTypes.h"
19 #include "llvm/ADT/SmallBitVector.h"
20 #include "llvm/ADT/SmallPtrSet.h"
21 #include "llvm/ADT/StringRef.h"
23 using namespace circt;
27 return attrs.getAs<::circt::hw::InnerSymAttr>(
28 hw::HWModuleLike::getPortSymbolAttrName());
35 NamedAttrList pattr(attrs);
38 oldValue = pattr.erase(portSymAttr);
40 oldValue = pattr.set(portSymAttr, sym);
41 if (oldValue != sym) {
42 attrs = pattr.getDictionary(ctx);
47 auto innerSym = op.getInnerSymAttr();
53 return op->emitOpError(
"has empty list of inner symbols");
55 if (!op.supportsPerFieldSymbols()) {
57 if (innerSym.size() > 1 || !innerSym.getSymName()) {
58 op->emitOpError(
"does not support per-field inner symbols");
64 auto result = op.getTargetResult();
70 auto resultType = result.getType();
72 llvm::SmallBitVector indices(maxFields + 1);
73 llvm::SmallPtrSet<Attribute, 8> symNames;
75 auto uniqSyms = [&](InnerSymPropertiesAttr p) {
76 if (maxFields < p.getFieldID()) {
77 op->emitOpError(
"field id:'" + Twine(p.getFieldID()) +
78 "' is greater than the maximum field id:'" +
79 Twine(maxFields) +
"'");
82 if (indices.test(p.getFieldID())) {
83 op->emitOpError(
"cannot assign multiple symbol names to the field id:'" +
84 Twine(p.getFieldID()) +
"'");
87 indices.set(p.getFieldID());
88 auto it = symNames.insert(p.getName());
90 op->emitOpError(
"cannot reuse symbol name:'" + p.getName().getValue() +
97 if (!llvm::all_of(innerSym.getProps(), uniqSyms))
116 printer << dirstr <<
" " << port.
name <<
" : " << port.
type <<
" (argnum "
118 <<
", args " << port.
attrs <<
")";
122 #include "circt/Dialect/HW/HWOpInterfaces.cpp.inc"
Direction get(bool isOutput)
Returns an output direction if isOutput is true, otherwise returns an input direction.
uint64_t getMaxFieldID(Type)
raw_ostream & operator<<(raw_ostream &printer, PortInfo port)
LogicalResult verifyInnerSymAttr(InnerSymbolOpInterface op)
Verification hook for verifying InnerSym Attribute.
This file defines an intermediate representation for circuits acting as an abstraction for constraint...
This holds the name, type, direction of a module's ports.
DictionaryAttr attrs
The optional symbol for this port.
size_t argNum
This is the argument index or the result index depending on the direction.
void setSym(InnerSymAttr sym, MLIRContext *ctx)
InnerSymAttr getSym() const