15#include "mlir/IR/Builders.h"
16#include "mlir/IR/BuiltinAttributes.h"
17#include "mlir/IR/DialectImplementation.h"
18#include "llvm/ADT/TypeSwitch.h"
23#define GET_ATTRDEF_CLASSES
24#include "circt/Dialect/MSFT/MSFTAttributes.cpp.inc"
26Attribute 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 =
43 PrimitiveTypeAttr::get(p.getContext(), *devType);
44 auto phy = PhysLocationAttr::get(p.getContext(), devTypeAttr, x, y, num);
48void PhysLocationAttr::print(AsmPrinter &p)
const {
49 p <<
"<" << stringifyPrimitiveType(getPrimitiveType().getValue()) <<
", "
50 << getX() <<
", " << getY() <<
", " << getNum() <<
'>';
53Attribute 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");
66 return PhysicalBoundsAttr::get(p.getContext(), xMin, xMax, yMin, yMax);
69void PhysicalBoundsAttr::print(AsmPrinter &p)
const {
71 p <<
"x: [" << getXMin() <<
", " << getXMax() <<
"], ";
72 p <<
"y: [" << getYMin() <<
", " << getYMax() <<
']';
76LogicalResult 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";
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));
113 if (loc && loc.getPrimitiveType().getValue() == PrimitiveType::FF)
114 p <<
'<' << loc.getX() <<
", " << loc.getY() <<
", " << loc.getNum() <<
'>';
121Attribute 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()),
137void LocationVectorAttr::print(AsmPrinter &p)
const {
138 p <<
'<' << getType() <<
", [";
139 llvm::interleaveComma(getLocs(), p, [&p](PhysLocationAttr loc) {
145void MSFTDialect::registerAttributes() {
147#define GET_ATTRDEF_LIST
148#include "circt/Dialect/MSFT/MSFTAttributes.cpp.inc"
LogicalResult parseOptionalRegLoc(SmallVectorImpl< PhysLocationAttr > &locs, AsmParser &p)
Parse and append a PhysLocAttr.
void printOptionalRegLoc(PhysLocationAttr loc, AsmPrinter &p)
Print out the above.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.