10#undef GET_ATTRDEF_LIST
17#ifdef GET_ATTRDEF_CLASSES
18#undef GET_ATTRDEF_CLASSES
20static ::mlir::OptionalParseResult generatedAttributeParser(::mlir::AsmParser &parser, ::llvm::StringRef *mnemonic, ::mlir::Type type, ::mlir::Attribute &value) {
21 return ::mlir::AsmParser::KeywordSwitch<::mlir::OptionalParseResult>(parser)
22 .Case(::llzk::PublicAttr::getMnemonic(), [&](llvm::StringRef, llvm::SMLoc) {
23 value = ::llzk::PublicAttr::get(parser.getContext());
24 return ::mlir::success(!!value);
26 .Case(::llzk::LoopBoundsAttr::getMnemonic(), [&](llvm::StringRef, llvm::SMLoc) {
27 value = ::llzk::LoopBoundsAttr::parse(parser, type);
28 return ::mlir::success(!!value);
30 .Default([&](llvm::StringRef keyword, llvm::SMLoc) {
36static ::mlir::LogicalResult generatedAttributePrinter(::mlir::Attribute def, ::mlir::AsmPrinter &printer) {
37 return ::llvm::TypeSwitch<::mlir::Attribute, ::mlir::LogicalResult>(def) .Case<::llzk::PublicAttr>([&](
auto t) {
38 printer << ::llzk::PublicAttr::getMnemonic();
39 return ::mlir::success();
41 .Case<::llzk::LoopBoundsAttr>([&](
auto t) {
42 printer << ::llzk::LoopBoundsAttr::getMnemonic();
44 return ::mlir::success();
46 .Default([](
auto) { return ::mlir::failure(); });
51MLIR_DEFINE_EXPLICIT_TYPE_ID(::llzk::PublicAttr)
54struct LoopBoundsAttrStorage :
public ::mlir::AttributeStorage {
55 using KeyTy = std::tuple<::llvm::APInt, ::llvm::APInt, ::llvm::APInt>;
56 LoopBoundsAttrStorage(::llvm::APInt lower, ::llvm::APInt upper, ::llvm::APInt step) : lower(std::move(lower)), upper(std::move(upper)), step(std::move(step)) {}
58 KeyTy getAsKey()
const {
59 return KeyTy(lower, upper, step);
62 bool operator==(
const KeyTy &tblgenKey)
const {
63 return (::llvm::APInt::isSameValue(lower, std::get<0>(tblgenKey))) && (::llvm::APInt::isSameValue(upper, std::get<1>(tblgenKey))) && (::llvm::APInt::isSameValue(step, std::get<2>(tblgenKey)));
66 static ::llvm::hash_code hashKey(
const KeyTy &tblgenKey) {
67 return ::llvm::hash_combine(std::get<0>(tblgenKey), std::get<1>(tblgenKey), std::get<2>(tblgenKey));
70 static LoopBoundsAttrStorage *construct(::mlir::AttributeStorageAllocator &allocator, KeyTy &&tblgenKey) {
71 auto lower = std::move(std::get<0>(tblgenKey));
72 auto upper = std::move(std::get<1>(tblgenKey));
73 auto step = std::move(std::get<2>(tblgenKey));
74 return new (allocator.allocate<LoopBoundsAttrStorage>()) LoopBoundsAttrStorage(std::move(lower), std::move(upper), std::move(step));
82LoopBoundsAttr LoopBoundsAttr::get(::mlir::MLIRContext *context, ::llvm::APInt lower, ::llvm::APInt upper, ::llvm::APInt step) {
83 return Base::get(context, std::move(lower), std::move(upper), std::move(step));
86::mlir::Attribute LoopBoundsAttr::parse(::mlir::AsmParser &odsParser, ::mlir::Type odsType) {
87 ::mlir::Builder odsBuilder(odsParser.getContext());
88 ::llvm::SMLoc odsLoc = odsParser.getCurrentLocation();
90 ::mlir::FailureOr<::llvm::APInt> _result_lower;
91 ::mlir::FailureOr<::llvm::APInt> _result_upper;
92 ::mlir::FailureOr<::llvm::APInt> _result_step;
94 if (odsParser.parseLess())
return {};
98 if (::mlir::failed(_result_lower)) {
99 odsParser.emitError(odsParser.getCurrentLocation(),
"failed to parse LLZK_LoopBoundsAttr parameter 'lower' which is to be a `::llvm::APInt`");
103 if (odsParser.parseKeyword(
"to"))
return {};
107 if (::mlir::failed(_result_upper)) {
108 odsParser.emitError(odsParser.getCurrentLocation(),
"failed to parse LLZK_LoopBoundsAttr parameter 'upper' which is to be a `::llvm::APInt`");
112 if (odsParser.parseKeyword(
"step"))
return {};
116 if (::mlir::failed(_result_step)) {
117 odsParser.emitError(odsParser.getCurrentLocation(),
"failed to parse LLZK_LoopBoundsAttr parameter 'step' which is to be a `::llvm::APInt`");
121 if (odsParser.parseGreater())
return {};
122 assert(::mlir::succeeded(_result_lower));
123 assert(::mlir::succeeded(_result_upper));
124 assert(::mlir::succeeded(_result_step));
125 return LoopBoundsAttr::get(odsParser.getContext(),
126 ::llvm::APInt((*_result_lower)),
127 ::llvm::APInt((*_result_upper)),
128 ::llvm::APInt((*_result_step)));
131void LoopBoundsAttr::print(::mlir::AsmPrinter &odsPrinter)
const {
132 ::mlir::Builder odsBuilder(getContext());
134 odsPrinter.printStrippedAttrOrType(getLower());
135 odsPrinter <<
' ' <<
"to";
137 odsPrinter.printStrippedAttrOrType(getUpper());
138 odsPrinter <<
' ' <<
"step";
140 odsPrinter.printStrippedAttrOrType(getStep());
144::llvm::APInt LoopBoundsAttr::getLower()
const {
145 return getImpl()->lower;
148::llvm::APInt LoopBoundsAttr::getUpper()
const {
149 return getImpl()->upper;
152::llvm::APInt LoopBoundsAttr::getStep()
const {
153 return getImpl()->step;
157MLIR_DEFINE_EXPLICIT_TYPE_ID(::llzk::LoopBoundsAttr)
162 ::mlir::Type type)
const {
163 ::llvm::SMLoc typeLoc = parser.getCurrentLocation();
164 ::llvm::StringRef attrTag;
166 ::mlir::Attribute attr;
167 auto parseResult = generatedAttributeParser(parser, &attrTag, type, attr);
168 if (parseResult.has_value())
172 parser.emitError(typeLoc) <<
"unknown attribute `"
173 << attrTag <<
"` in dialect `" << getNamespace() <<
"`";
178 ::mlir::DialectAsmPrinter &printer)
const {
179 if (::mlir::succeeded(generatedAttributePrinter(attr, printer)))
::mlir::Attribute parseAttribute(::mlir::DialectAsmParser &parser, ::mlir::Type type) const override
Parse an attribute registered to this dialect.
void printAttribute(::mlir::Attribute attr, ::mlir::DialectAsmPrinter &os) const override
Print an attribute registered to this dialect.