LLZK 3.0.0
An open-source IR for Zero Knowledge (ZK) circuits
Loading...
Searching...
No Matches
Types.cpp.inc
Go to the documentation of this file.
1/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\
2|* *|
3|* TypeDef Definitions *|
4|* *|
5|* Automatically generated file, do not edit! *|
6|* *|
7\*===----------------------------------------------------------------------===*/
8
9#ifdef GET_TYPEDEF_LIST
10#undef GET_TYPEDEF_LIST
11
13
14#endif // GET_TYPEDEF_LIST
15
16#ifdef GET_TYPEDEF_CLASSES
17#undef GET_TYPEDEF_CLASSES
18
19static ::mlir::OptionalParseResult generatedTypeParser(::mlir::AsmParser &parser, ::llvm::StringRef *mnemonic, ::mlir::Type &value) {
20 return ::mlir::AsmParser::KeywordSwitch<::mlir::OptionalParseResult>(parser)
21 .Case(::llzk::array::ArrayType::getMnemonic(), [&](llvm::StringRef, llvm::SMLoc) {
22 value = ::llzk::array::ArrayType::parse(parser);
23 return ::mlir::success(!!value);
24 })
25 .Default([&](llvm::StringRef keyword, llvm::SMLoc) {
26 *mnemonic = keyword;
27 return std::nullopt;
28 });
29}
30
31static ::llvm::LogicalResult generatedTypePrinter(::mlir::Type def, ::mlir::AsmPrinter &printer) {
32 return ::llvm::TypeSwitch<::mlir::Type, ::llvm::LogicalResult>(def) .Case<::llzk::array::ArrayType>([&](auto t) {
34t.print(printer);
35 return ::mlir::success();
36 })
37 .Default([](auto) { return ::mlir::failure(); });
38}
39
40namespace llzk::array {
41
42namespace detail {
43
44struct ArrayTypeStorage : public ::mlir::TypeStorage {
45 using KeyTy = std::tuple<::mlir::Type, ::llvm::ArrayRef<::mlir::Attribute>, ::llvm::ArrayRef<int64_t>>;
46 ArrayTypeStorage(::mlir::Type elementType, ::llvm::ArrayRef<::mlir::Attribute> dimensionSizes, ::llvm::ArrayRef<int64_t> shape) : elementType(std::move(elementType)), dimensionSizes(std::move(dimensionSizes)), shape(std::move(shape)) {}
47
48 KeyTy getAsKey() const {
50 }
51
52 bool operator==(const KeyTy &tblgenKey) const {
53 return (elementType == std::get<0>(tblgenKey)) && (dimensionSizes == std::get<1>(tblgenKey)) && (shape == std::get<2>(tblgenKey));
54 }
55
56 static ::llvm::hash_code hashKey(const KeyTy &tblgenKey) {
57 return ::llvm::hash_combine(std::get<0>(tblgenKey), std::get<1>(tblgenKey), std::get<2>(tblgenKey));
58 }
59
60 static ArrayTypeStorage *construct(::mlir::TypeStorageAllocator &allocator, KeyTy &&tblgenKey) {
61 auto elementType = std::move(std::get<0>(tblgenKey));
62 auto dimensionSizes = std::move(std::get<1>(tblgenKey));
63 auto shape = std::move(std::get<2>(tblgenKey));
64 dimensionSizes = allocator.copyInto(dimensionSizes);
65 shape = allocator.copyInto(shape);
66 return new (allocator.allocate<ArrayTypeStorage>()) ArrayTypeStorage(std::move(elementType), std::move(dimensionSizes), std::move(shape));
67 }
68
69 ::mlir::Type elementType;
70 ::llvm::ArrayRef<::mlir::Attribute> dimensionSizes;
71 ::llvm::ArrayRef<int64_t> shape;
72};
73
74} // namespace detail
75namespace {
83 const ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError = nullptr;
84}
85ArrayType ArrayType::get(::mlir::Type elementType, ::llvm::ArrayRef<::mlir::Attribute> dimensionSizes) {
86 assert(elementType && "element type cannot be null");
87 ::mlir::MLIRContext *ctx = elementType.getContext();
89 auto dimSizesRes = forceIntAttrTypes(dimensionSizes, emitErrorFn);
90 if(::mlir::failed(dimSizesRes)) { return ArrayType(); }
91 ::llvm::SmallVector<::mlir::Attribute> dimSizes = *dimSizesRes;
92 ::llvm::SmallVector<int64_t> shape;
93 ::mlir::LogicalResult res = computeShapeFromDims(emitErrorFn, dimSizes, shape);
94 if(::mlir::failed(res)) { return ArrayType(); }
95 return Base::get(ctx, elementType, dimSizes, shape);
96}
97
98ArrayType ArrayType::getChecked(::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, ::mlir::Type elementType, ::llvm::ArrayRef<::mlir::Attribute> dimensionSizes) {
99 assert(elementType && "element type cannot be null");
100 ::mlir::MLIRContext *ctx = elementType.getContext();
101 OwningEmitErrorFn emitErrorFn = ::llzk::wrapNullableInFlightDiagnostic(emitError, ctx);
102 auto dimSizesRes = forceIntAttrTypes(dimensionSizes, emitErrorFn);
103 if(::mlir::failed(dimSizesRes)) { return ArrayType(); }
104 ::llvm::SmallVector<::mlir::Attribute> dimSizes = *dimSizesRes;
105 ::llvm::SmallVector<int64_t> shape;
106 ::mlir::LogicalResult res = computeShapeFromDims(emitErrorFn, dimSizes, shape);
107 if(::mlir::failed(res)) { return ArrayType(); }
108 return Base::getChecked(emitError, ctx, elementType, dimSizes, shape);
109}
110
111ArrayType ArrayType::get(::mlir::Type elementType, ::llvm::ArrayRef<int64_t> shape) {
112 assert(elementType && "element type cannot be null");
113 ::mlir::MLIRContext *ctx = elementType.getContext();
114 ::llvm::SmallVector<::mlir::Attribute> dimSizes;
115 ::mlir::LogicalResult res = computeDimsFromShape(ctx, shape, dimSizes);
116 if(::mlir::failed(res)) { return ArrayType(); }
117 return Base::get(ctx, elementType, dimSizes, shape);
118}
119
120ArrayType ArrayType::getChecked(::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, ::mlir::Type elementType, ::llvm::ArrayRef<int64_t> shape) {
121 assert(elementType && "element type cannot be null");
122 ::mlir::MLIRContext *ctx = elementType.getContext();
123 ::llvm::SmallVector<::mlir::Attribute> dimSizes;
124 ::mlir::LogicalResult res = computeDimsFromShape(ctx, shape, dimSizes);
125 if(::mlir::failed(res)) { return ArrayType(); }
126 return Base::getChecked(emitError, ctx, elementType, dimSizes, shape);
127}
128
129::llvm::LogicalResult ArrayType::verifyInvariants(::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, ::mlir::Type elementType, ::llvm::ArrayRef<::mlir::Attribute> dimensionSizes, ::llvm::ArrayRef<int64_t> shape) {
130 if (::mlir::failed(verify(emitError, elementType, dimensionSizes, shape)))
131 return ::mlir::failure();
132 return ::mlir::success();
133}
134
135::mlir::Type ArrayType::parse(::mlir::AsmParser &odsParser) {
136 ::mlir::Builder odsBuilder(odsParser.getContext());
137 ::llvm::SMLoc odsLoc = odsParser.getCurrentLocation();
138 (void) odsLoc;
139 ::mlir::FailureOr<::mlir::Type> _result_elementType;
140 ::mlir::FailureOr<::llvm::SmallVector<::mlir::Attribute>> _result_dimensionSizes;
141 ::mlir::FailureOr<::llvm::SmallVector<int64_t>> _result_shape;
142 // Parse literal '<'
143 if (odsParser.parseLess()) return {};
144 {
145 auto odsCustomLoc = odsParser.getCurrentLocation();
146 (void)odsCustomLoc;
147 auto odsCustomResult = parseAttrVec(odsParser,
148 ::mlir::detail::unwrapForCustomParse(_result_dimensionSizes));
149 if (::mlir::failed(odsCustomResult)) return {};
150 if (::mlir::failed(_result_dimensionSizes)) {
151 odsParser.emitError(odsCustomLoc, "custom parser failed to parse parameter 'dimensionSizes'");
152 return {};
153 }
154 }
155 {
156 auto odsCustomLoc = odsParser.getCurrentLocation();
157 (void)odsCustomLoc;
158 auto odsCustomResult = parseDerivedShape(odsParser,
159 ::mlir::detail::unwrapForCustomParse(_result_shape),
160 *_result_dimensionSizes);
161 if (::mlir::failed(odsCustomResult)) return {};
162 if (::mlir::failed(_result_shape)) {
163 odsParser.emitError(odsCustomLoc, "custom parser failed to parse parameter 'shape'");
164 return {};
165 }
166 }
167 // Parse literal 'x'
168 if (odsParser.parseKeyword("x")) return {};
169
170 // Parse variable 'elementType'
171 _result_elementType = ::mlir::FieldParser<::mlir::Type>::parse(odsParser);
172 if (::mlir::failed(_result_elementType)) {
173 odsParser.emitError(odsParser.getCurrentLocation(), "failed to parse LLZK_ArrayType parameter 'elementType' which is to be a `::mlir::Type`");
174 return {};
175 }
176 // Parse literal '>'
177 if (odsParser.parseGreater()) return {};
178 assert(::mlir::succeeded(_result_elementType));
179 assert(::mlir::succeeded(_result_dimensionSizes));
180 assert(::mlir::succeeded(_result_shape));
181 return odsParser.getChecked<ArrayType>(odsLoc, odsParser.getContext(),
182 ::mlir::Type((*_result_elementType)),
183 ::llvm::ArrayRef<::mlir::Attribute>((*_result_dimensionSizes)),
184 ::llvm::ArrayRef<int64_t>((*_result_shape)));
185}
186
187void ArrayType::print(::mlir::AsmPrinter &odsPrinter) const {
188 ::mlir::Builder odsBuilder(getContext());
189 odsPrinter << "<";
190 printAttrVec(odsPrinter,
192 printDerivedShape(odsPrinter,
193 getShape(),
195 odsPrinter << ' ' << "x";
196 odsPrinter << ' ';
197 odsPrinter.printStrippedAttrOrType(getElementType());
198 odsPrinter << ">";
199}
200
201::mlir::Type ArrayType::getElementType() const {
202 return getImpl()->elementType;
203}
204
205::llvm::ArrayRef<::mlir::Attribute> ArrayType::getDimensionSizes() const {
206 return getImpl()->dimensionSizes;
207}
208
209::llvm::ArrayRef<int64_t> ArrayType::getShape() const {
210 return getImpl()->shape;
211}
212
213
214} // namespace llzk::array
215MLIR_DEFINE_EXPLICIT_TYPE_ID(::llzk::array::ArrayType)
216namespace llzk::array {
217
218
220::mlir::Type ArrayDialect::parseType(::mlir::DialectAsmParser &parser) const {
221 ::llvm::SMLoc typeLoc = parser.getCurrentLocation();
222 ::llvm::StringRef mnemonic;
223 ::mlir::Type genType;
224 auto parseResult = generatedTypeParser(parser, &mnemonic, genType);
225 if (parseResult.has_value())
226 return genType;
227
228 parser.emitError(typeLoc) << "unknown type `"
229 << mnemonic << "` in dialect `" << getNamespace() << "`";
230 return {};
231}
232
233void ArrayDialect::printType(::mlir::Type type,
234 ::mlir::DialectAsmPrinter &printer) const {
235 if (::mlir::succeeded(generatedTypePrinter(type, printer)))
236 return;
237
238}
239
240} // namespace llzk::array
241
242#endif // GET_TYPEDEF_CLASSES
243
::mlir::Type parseType(::mlir::DialectAsmParser &parser) const override
Parse a type registered to this dialect.
void printType(::mlir::Type type, ::mlir::DialectAsmPrinter &os) const override
Print a type registered to this dialect.
::mlir::Type parse(::mlir::AsmParser &odsParser)
static constexpr ::llvm::StringLiteral getMnemonic()
Definition Types.h.inc:90
::llvm::LogicalResult verifyInvariants(::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, ::mlir::Type elementType, ::llvm::ArrayRef<::mlir::Attribute > dimensionSizes, ::llvm::ArrayRef< int64_t > shape)
void print(::mlir::AsmPrinter &odsPrinter) const
::llvm::ArrayRef< int64_t > getShape() const
::mlir::Type getElementType() const
static ArrayType get(::mlir::Type elementType, ::llvm::ArrayRef<::mlir::Attribute > dimensionSizes)
Definition Types.cpp.inc:85
static ArrayType getChecked(::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, ::mlir::Type elementType, ::llvm::ArrayRef<::mlir::Attribute > dimensionSizes)
Definition Types.cpp.inc:98
::llvm::LogicalResult verify(::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, ::mlir::Type elementType, ::llvm::ArrayRef<::mlir::Attribute > dimensionSizes, ::llvm::ArrayRef< int64_t > shape)
Definition Types.cpp:75
::llvm::ArrayRef<::mlir::Attribute > getDimensionSizes() const
Common interface for operations that reference an array value.
LogicalResult computeShapeFromDims(EmitErrorFn emitError, ArrayRef< Attribute > dimensionSizes, SmallVector< int64_t > &shape)
Definition Types.cpp:33
ParseResult parseAttrVec(AsmParser &parser, SmallVector< Attribute > &value)
Definition Types.cpp:157
void printDerivedShape(AsmPrinter &, ArrayRef< int64_t >, ArrayRef< Attribute >)
Definition Types.cpp:71
LogicalResult computeDimsFromShape(MLIRContext *ctx, ArrayRef< int64_t > shape, SmallVector< Attribute > &dimensionSizes)
Definition Types.cpp:22
void printAttrVec(AsmPrinter &printer, ArrayRef< Attribute > value)
Definition Types.cpp:185
ParseResult parseDerivedShape(AsmParser &parser, SmallVector< int64_t > &shape, SmallVector< Attribute > dimensionSizes)
Definition Types.cpp:60
FailureOr< SmallVector< Attribute > > forceIntAttrTypes(ArrayRef< Attribute > attrList, EmitErrorFn emitError)
std::function< InFlightDiagnosticWrapper()> OwningEmitErrorFn
This type is required in cases like the functions below to take ownership of the lambda so it is not ...
OwningEmitErrorFn wrapNullableInFlightDiagnostic(llvm::function_ref< mlir::InFlightDiagnostic()> emitError, mlir::MLIRContext *ctx)
If the given emitError is non-null, return it.
std::tuple<::mlir::Type, ::llvm::ArrayRef<::mlir::Attribute >, ::llvm::ArrayRef< int64_t > > KeyTy
Definition Types.cpp.inc:45
static ArrayTypeStorage * construct(::mlir::TypeStorageAllocator &allocator, KeyTy &&tblgenKey)
Definition Types.cpp.inc:60
::llvm::ArrayRef<::mlir::Attribute > dimensionSizes
Definition Types.cpp.inc:70
bool operator==(const KeyTy &tblgenKey) const
Definition Types.cpp.inc:52
ArrayTypeStorage(::mlir::Type elementType, ::llvm::ArrayRef<::mlir::Attribute > dimensionSizes, ::llvm::ArrayRef< int64_t > shape)
Definition Types.cpp.inc:46
::llvm::ArrayRef< int64_t > shape
Definition Types.cpp.inc:71
::llvm::hash_code hashKey(const KeyTy &tblgenKey)
Definition Types.cpp.inc:56