15 #include "mlir/IR/Builders.h"
16 #include "mlir/IR/BuiltinAttributes.h"
17 #include "mlir/IR/DialectImplementation.h"
18 #include "llvm/ADT/TypeSwitch.h"
20 using namespace circt;
23 #define GET_ATTRDEF_CLASSES
24 #include "circt/Dialect/MSFT/MSFTAttributes.cpp.inc"
26 Attribute PhysLocationAttr::parse(AsmParser &p, Type type) {
27 llvm::SMLoc loc = p.getCurrentLocation();
32 if (p.parseLess() || p.parseKeyword(&devTypeStr) || p.parseComma() ||
33 p.parseInteger(x) || p.parseComma() || p.parseInteger(y) ||
34 p.parseComma() || p.parseInteger(num) || p.parseGreater())
37 std::optional<PrimitiveType> devType = symbolizePrimitiveType(devTypeStr);
39 p.emitError(loc,
"Unknown device type '" + devTypeStr +
"'");
42 PrimitiveTypeAttr devTypeAttr =
48 void PhysLocationAttr::print(AsmPrinter &p)
const {
49 p <<
"<" << stringifyPrimitiveType(getPrimitiveType().getValue()) <<
", "
50 << getX() <<
", " << getY() <<
", " << getNum() <<
'>';
53 Attribute PhysicalBoundsAttr::parse(AsmParser &p, Type type) {
54 uint64_t xMin, xMax, yMin, yMax;
55 if (p.parseLess() || p.parseKeyword(
"x") || p.parseColon() ||
56 p.parseLSquare() || p.parseInteger(xMin) || p.parseComma() ||
57 p.parseInteger(xMax) || p.parseRSquare() || p.parseComma() ||
58 p.parseKeyword(
"y") || p.parseColon() || p.parseLSquare() ||
59 p.parseInteger(yMin) || p.parseComma() || p.parseInteger(yMax) ||
60 p.parseRSquare() || p.parseGreater()) {
61 llvm::SMLoc loc = p.getCurrentLocation();
62 p.emitError(loc,
"unable to parse PhysicalBounds");
69 void PhysicalBoundsAttr::print(AsmPrinter &p)
const {
71 p <<
"x: [" << getXMin() <<
", " << getXMax() <<
"], ";
72 p <<
"y: [" << getYMin() <<
", " << getYMax() <<
']';
76 LogicalResult LocationVectorAttr::verify(
77 llvm::function_ref<mlir::InFlightDiagnostic()> emitError, TypeAttr type,
78 ArrayRef<PhysLocationAttr> locs) {
79 int64_t typeBitWidth = hw::getBitWidth(type.getValue());
81 return emitError() << "cannot compute bit width of type '" << type << "'";
82 if ((uint64_t)typeBitWidth != locs.size())
83 return emitError() << "must specify " << typeBitWidth << " locations";
88 circt::msft::parseOptionalRegLoc(SmallVectorImpl<PhysLocationAttr> &locs,
90 MLIRContext *ctxt = p.getContext();
91 if (!p.parseOptionalStar()) {
97 if (p.parseOptionalAttribute(loc).has_value()) {
103 if (p.parseLess() || p.parseInteger(x) || p.parseComma() ||
104 p.parseInteger(y) || p.parseComma() || p.parseInteger(n) ||
107 locs.push_back(PhysLocationAttr::get(
108 ctxt, PrimitiveTypeAttr::get(ctxt, PrimitiveType::FF), x, y, n));
112 void circt::msft::printOptionalRegLoc(PhysLocationAttr loc, AsmPrinter &p) {
113 if (loc && loc.getPrimitiveType().getValue() == PrimitiveType::FF)
114 p << '<
' << loc.getX() << ", " << loc.getY() << ", " << loc.getNum() << '>
';
121 Attribute LocationVectorAttr::parse(AsmParser &p, Type) {
122 MLIRContext *ctxt = p.getContext();
124 SmallVector<PhysLocationAttr, 32> locs;
126 if (p.parseLess() || p.parseAttribute(type) || p.parseComma() ||
127 p.parseLSquare() || p.parseCommaSeparatedList([&]() {
128 return parseOptionalRegLoc(locs, p);
130 p.parseRSquare() || p.parseGreater())
133 return LocationVectorAttr::getChecked(p.getEncodedSourceLoc(p.getNameLoc()),
137 void LocationVectorAttr::print(AsmPrinter &p) const {
138 p << '<
' << getType() << ", [";
139 llvm::interleaveComma(getLocs(), p, [&p](PhysLocationAttr loc) {
140 printOptionalRegLoc(loc, p);
145 void MSFTDialect::registerAttributes() {
147 #define GET_ATTRDEF_LIST
148 #include "circt/Dialect/MSFT/MSFTAttributes.cpp.inc"
Direction get(bool isOutput)
Returns an output direction if isOutput is true, otherwise returns an input direction.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.