LLZK 0.1.0
Veridise's ZK Language IR
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 {
41namespace array {
42namespace detail {
43struct ArrayTypeStorage : public ::mlir::TypeStorage {
44 using KeyTy = std::tuple<::mlir::Type, ::llvm::ArrayRef<::mlir::Attribute>, ::llvm::ArrayRef<int64_t>>;
45 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)) {}
46
47 KeyTy getAsKey() const {
49 }
50
51 bool operator==(const KeyTy &tblgenKey) const {
52 return (elementType == std::get<0>(tblgenKey)) && (dimensionSizes == std::get<1>(tblgenKey)) && (shape == std::get<2>(tblgenKey));
53 }
54
55 static ::llvm::hash_code hashKey(const KeyTy &tblgenKey) {
56 return ::llvm::hash_combine(std::get<0>(tblgenKey), std::get<1>(tblgenKey), std::get<2>(tblgenKey));
57 }
58
59 static ArrayTypeStorage *construct(::mlir::TypeStorageAllocator &allocator, KeyTy &&tblgenKey) {
60 auto elementType = std::move(std::get<0>(tblgenKey));
61 auto dimensionSizes = std::move(std::get<1>(tblgenKey));
62 auto shape = std::move(std::get<2>(tblgenKey));
63 dimensionSizes = allocator.copyInto(dimensionSizes);
64 shape = allocator.copyInto(shape);
65 return new (allocator.allocate<ArrayTypeStorage>()) ArrayTypeStorage(std::move(elementType), std::move(dimensionSizes), std::move(shape));
66 }
67
68 ::mlir::Type elementType;
69 ::llvm::ArrayRef<::mlir::Attribute> dimensionSizes;
70 ::llvm::ArrayRef<int64_t> shape;
71};
72} // namespace detail
73namespace {
81 const ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError = nullptr;
82}
83ArrayType ArrayType::get(::mlir::Type elementType, ::llvm::ArrayRef<::mlir::Attribute> dimensionSizes) {
84 assert(elementType && "element type cannot be null");
85 ::mlir::MLIRContext *ctx = elementType.getContext();
87 auto dimSizesRes = forceIntAttrTypes(dimensionSizes, emitErrorFn);
88 if(::mlir::failed(dimSizesRes)) { return ArrayType(); }
89 ::llvm::SmallVector<::mlir::Attribute> dimSizes = *dimSizesRes;
90 ::llvm::SmallVector<int64_t> shape;
91 ::mlir::LogicalResult res = computeShapeFromDims(emitErrorFn, dimSizes, shape);
92 if(::mlir::failed(res)) { return ArrayType(); }
93 return Base::get(ctx, elementType, dimSizes, shape);
94}
95
96ArrayType ArrayType::getChecked(::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, ::mlir::Type elementType, ::llvm::ArrayRef<::mlir::Attribute> dimensionSizes) {
97 assert(elementType && "element type cannot be null");
98 ::mlir::MLIRContext *ctx = elementType.getContext();
100 auto dimSizesRes = forceIntAttrTypes(dimensionSizes, emitErrorFn);
101 if(::mlir::failed(dimSizesRes)) { return ArrayType(); }
102 ::llvm::SmallVector<::mlir::Attribute> dimSizes = *dimSizesRes;
103 ::llvm::SmallVector<int64_t> shape;
104 ::mlir::LogicalResult res = computeShapeFromDims(emitErrorFn, dimSizes, shape);
105 if(::mlir::failed(res)) { return ArrayType(); }
106 return Base::getChecked(emitError, ctx, elementType, dimSizes, shape);
107}
108
109ArrayType ArrayType::get(::mlir::Type elementType, ::llvm::ArrayRef<int64_t> shape) {
110 assert(elementType && "element type cannot be null");
111 ::mlir::MLIRContext *ctx = elementType.getContext();
112 ::llvm::SmallVector<::mlir::Attribute> dimSizes;
113 ::mlir::LogicalResult res = computeDimsFromShape(ctx, shape, dimSizes);
114 if(::mlir::failed(res)) { return ArrayType(); }
115 return Base::get(ctx, elementType, dimSizes, shape);
116}
117
118ArrayType ArrayType::getChecked(::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, ::mlir::Type elementType, ::llvm::ArrayRef<int64_t> shape) {
119 assert(elementType && "element type cannot be null");
120 ::mlir::MLIRContext *ctx = elementType.getContext();
121 ::llvm::SmallVector<::mlir::Attribute> dimSizes;
122 ::mlir::LogicalResult res = computeDimsFromShape(ctx, shape, dimSizes);
123 if(::mlir::failed(res)) { return ArrayType(); }
124 return Base::getChecked(emitError, ctx, elementType, dimSizes, shape);
125}
126
127::llvm::LogicalResult ArrayType::verifyInvariants(::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, ::mlir::Type elementType, ::llvm::ArrayRef<::mlir::Attribute> dimensionSizes, ::llvm::ArrayRef<int64_t> shape) {
128 if (::mlir::failed(verify(emitError, elementType, dimensionSizes, shape)))
129 return ::mlir::failure();
130 return ::mlir::success();
131}
132
133::mlir::Type ArrayType::parse(::mlir::AsmParser &odsParser) {
134 ::mlir::Builder odsBuilder(odsParser.getContext());
135 ::llvm::SMLoc odsLoc = odsParser.getCurrentLocation();
136 (void) odsLoc;
137 ::mlir::FailureOr<::mlir::Type> _result_elementType;
138 ::mlir::FailureOr<::llvm::SmallVector<::mlir::Attribute>> _result_dimensionSizes;
139 ::mlir::FailureOr<::llvm::SmallVector<int64_t>> _result_shape;
140 // Parse literal '<'
141 if (odsParser.parseLess()) return {};
142 {
143 auto odsCustomLoc = odsParser.getCurrentLocation();
144 (void)odsCustomLoc;
145 auto odsCustomResult = parseAttrVec(odsParser,
146 ::mlir::detail::unwrapForCustomParse(_result_dimensionSizes));
147 if (::mlir::failed(odsCustomResult)) return {};
148 if (::mlir::failed(_result_dimensionSizes)) {
149 odsParser.emitError(odsCustomLoc, "custom parser failed to parse parameter 'dimensionSizes'");
150 return {};
151 }
152 }
153 {
154 auto odsCustomLoc = odsParser.getCurrentLocation();
155 (void)odsCustomLoc;
156 auto odsCustomResult = parseDerivedShape(odsParser,
157 ::mlir::detail::unwrapForCustomParse(_result_shape),
158 *_result_dimensionSizes);
159 if (::mlir::failed(odsCustomResult)) return {};
160 if (::mlir::failed(_result_shape)) {
161 odsParser.emitError(odsCustomLoc, "custom parser failed to parse parameter 'shape'");
162 return {};
163 }
164 }
165 // Parse literal 'x'
166 if (odsParser.parseKeyword("x")) return {};
167
168 // Parse variable 'elementType'
169 _result_elementType = ::mlir::FieldParser<::mlir::Type>::parse(odsParser);
170 if (::mlir::failed(_result_elementType)) {
171 odsParser.emitError(odsParser.getCurrentLocation(), "failed to parse LLZK_ArrayType parameter 'elementType' which is to be a `::mlir::Type`");
172 return {};
173 }
174 // Parse literal '>'
175 if (odsParser.parseGreater()) return {};
176 assert(::mlir::succeeded(_result_elementType));
177 assert(::mlir::succeeded(_result_dimensionSizes));
178 assert(::mlir::succeeded(_result_shape));
179 return odsParser.getChecked<ArrayType>(odsLoc, odsParser.getContext(),
180 ::mlir::Type((*_result_elementType)),
181 ::llvm::ArrayRef<::mlir::Attribute>((*_result_dimensionSizes)),
182 ::llvm::ArrayRef<int64_t>((*_result_shape)));
183}
184
185void ArrayType::print(::mlir::AsmPrinter &odsPrinter) const {
186 ::mlir::Builder odsBuilder(getContext());
187 odsPrinter << "<";
188 printAttrVec(odsPrinter,
190 printDerivedShape(odsPrinter,
191 getShape(),
193 odsPrinter << ' ' << "x";
194 odsPrinter << ' ';
195 odsPrinter.printStrippedAttrOrType(getElementType());
196 odsPrinter << ">";
197}
198
199::mlir::Type ArrayType::getElementType() const {
200 return getImpl()->elementType;
201}
202
203::llvm::ArrayRef<::mlir::Attribute> ArrayType::getDimensionSizes() const {
204 return getImpl()->dimensionSizes;
205}
206
207::llvm::ArrayRef<int64_t> ArrayType::getShape() const {
208 return getImpl()->shape;
209}
210
211} // namespace array
212} // namespace llzk
213MLIR_DEFINE_EXPLICIT_TYPE_ID(::llzk::array::ArrayType)
214namespace llzk {
215namespace array {
216
218::mlir::Type ArrayDialect::parseType(::mlir::DialectAsmParser &parser) const {
219 ::llvm::SMLoc typeLoc = parser.getCurrentLocation();
220 ::llvm::StringRef mnemonic;
221 ::mlir::Type genType;
222 auto parseResult = generatedTypeParser(parser, &mnemonic, genType);
223 if (parseResult.has_value())
224 return genType;
225
226 parser.emitError(typeLoc) << "unknown type `"
227 << mnemonic << "` in dialect `" << getNamespace() << "`";
228 return {};
229}
230
231void ArrayDialect::printType(::mlir::Type type,
232 ::mlir::DialectAsmPrinter &printer) const {
233 if (::mlir::succeeded(generatedTypePrinter(type, printer)))
234 return;
235
236}
237} // namespace array
238} // namespace llzk
239
240#endif // GET_TYPEDEF_CLASSES
241
::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:60
::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:83
static ArrayType getChecked(::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, ::mlir::Type elementType, ::llvm::ArrayRef<::mlir::Attribute > dimensionSizes)
Definition Types.cpp.inc:96
::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:73
::llvm::ArrayRef<::mlir::Attribute > getDimensionSizes() const
LogicalResult computeShapeFromDims(EmitErrorFn emitError, ArrayRef< Attribute > dimensionSizes, SmallVector< int64_t > &shape)
Definition Types.cpp:32
ParseResult parseAttrVec(AsmParser &parser, SmallVector< Attribute > &value)
Definition Types.cpp:143
void printDerivedShape(AsmPrinter &, ArrayRef< int64_t >, ArrayRef< Attribute >)
Definition Types.cpp:69
LogicalResult computeDimsFromShape(MLIRContext *ctx, ArrayRef< int64_t > shape, SmallVector< Attribute > &dimensionSizes)
Definition Types.cpp:21
void printAttrVec(AsmPrinter &printer, ArrayRef< Attribute > value)
Definition Types.cpp:171
ParseResult parseDerivedShape(AsmParser &parser, SmallVector< int64_t > &shape, SmallVector< Attribute > dimensionSizes)
Definition Types.cpp:59
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:44
static ArrayTypeStorage * construct(::mlir::TypeStorageAllocator &allocator, KeyTy &&tblgenKey)
Definition Types.cpp.inc:59
::llvm::ArrayRef<::mlir::Attribute > dimensionSizes
Definition Types.cpp.inc:69
bool operator==(const KeyTy &tblgenKey) const
Definition Types.cpp.inc:51
ArrayTypeStorage(::mlir::Type elementType, ::llvm::ArrayRef<::mlir::Attribute > dimensionSizes, ::llvm::ArrayRef< int64_t > shape)
Definition Types.cpp.inc:45
::llvm::ArrayRef< int64_t > shape
Definition Types.cpp.inc:70
::llvm::hash_code hashKey(const KeyTy &tblgenKey)
Definition Types.cpp.inc:55