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 ::mlir::LogicalResult generatedTypePrinter(::mlir::Type def, ::mlir::AsmPrinter &printer) {
32 return ::llvm::TypeSwitch<::mlir::Type, ::mlir::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 ::llzk::EmitErrorFn emitError = nullptr;
82}
83ArrayType ArrayType::get(::mlir::Type elementType, ::llvm::ArrayRef<::mlir::Attribute> dimensionSizes) {
84 assert(elementType && "element type cannot be null");
85 ::llvm::SmallVector<::mlir::Attribute> dimSizes = forceIntAttrTypes(dimensionSizes);
86 ::mlir::MLIRContext *ctx = elementType.getContext();
87 ::llvm::SmallVector<int64_t> shape;
88 ::mlir::LogicalResult res = computeShapeFromDims(emitError, ctx, dimSizes, shape);
89 if(::mlir::failed(res)) { return ArrayType(); }
90 return Base::get(ctx, elementType, dimSizes, shape);
91}
92
93ArrayType ArrayType::getChecked(::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, ::mlir::Type elementType, ::llvm::ArrayRef<::mlir::Attribute> dimensionSizes) {
94 assert(elementType && "element type cannot be null");
95 ::llvm::SmallVector<::mlir::Attribute> dimSizes = forceIntAttrTypes(dimensionSizes);
96 ::mlir::MLIRContext *ctx = elementType.getContext();
97 ::llvm::SmallVector<int64_t> shape;
98 ::mlir::LogicalResult res = computeShapeFromDims(emitError, ctx, dimSizes, shape);
99 if(::mlir::failed(res)) { return ArrayType(); }
100 return Base::getChecked(emitError, ctx, elementType, dimSizes, shape);
101}
102
103ArrayType ArrayType::get(::mlir::Type elementType, ::llvm::ArrayRef<int64_t> shape) {
104 assert(elementType && "element type cannot be null");
105 ::mlir::MLIRContext *ctx = elementType.getContext();
106 ::llvm::SmallVector<::mlir::Attribute> dimSizes;
107 ::mlir::LogicalResult res = computeDimsFromShape(ctx, shape, dimSizes);
108 if(::mlir::failed(res)) { return ArrayType(); }
109 return Base::get(ctx, elementType, dimSizes, shape);
110}
111
112ArrayType ArrayType::getChecked(::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, ::mlir::Type elementType, ::llvm::ArrayRef<int64_t> shape) {
113 assert(elementType && "element type cannot be null");
114 ::mlir::MLIRContext *ctx = elementType.getContext();
115 ::llvm::SmallVector<::mlir::Attribute> dimSizes;
116 ::mlir::LogicalResult res = computeDimsFromShape(ctx, shape, dimSizes);
117 if(::mlir::failed(res)) { return ArrayType(); }
118 return Base::getChecked(emitError, ctx, elementType, dimSizes, shape);
119}
120
121::mlir::Type ArrayType::parse(::mlir::AsmParser &odsParser) {
122 ::mlir::Builder odsBuilder(odsParser.getContext());
123 ::llvm::SMLoc odsLoc = odsParser.getCurrentLocation();
124 (void) odsLoc;
125 ::mlir::FailureOr<::mlir::Type> _result_elementType;
126 ::mlir::FailureOr<::llvm::SmallVector<::mlir::Attribute>> _result_dimensionSizes;
127 ::mlir::FailureOr<::llvm::SmallVector<int64_t>> _result_shape;
128 // Parse literal '<'
129 if (odsParser.parseLess()) return {};
130 {
131 auto odsCustomLoc = odsParser.getCurrentLocation();
132 (void)odsCustomLoc;
133 auto odsCustomResult = parseAttrVec(odsParser,
134 ::mlir::detail::unwrapForCustomParse(_result_dimensionSizes));
135 if (::mlir::failed(odsCustomResult)) return {};
136 if (::mlir::failed(_result_dimensionSizes)) {
137 odsParser.emitError(odsCustomLoc, "custom parser failed to parse parameter 'dimensionSizes'");
138 return {};
139 }
140 }
141 {
142 auto odsCustomLoc = odsParser.getCurrentLocation();
143 (void)odsCustomLoc;
144 auto odsCustomResult = parseDerivedShape(odsParser,
145 ::mlir::detail::unwrapForCustomParse(_result_shape),
146 *_result_dimensionSizes);
147 if (::mlir::failed(odsCustomResult)) return {};
148 if (::mlir::failed(_result_shape)) {
149 odsParser.emitError(odsCustomLoc, "custom parser failed to parse parameter 'shape'");
150 return {};
151 }
152 }
153 // Parse literal 'x'
154 if (odsParser.parseKeyword("x")) return {};
155
156 // Parse variable 'elementType'
157 _result_elementType = ::mlir::FieldParser<::mlir::Type>::parse(odsParser);
158 if (::mlir::failed(_result_elementType)) {
159 odsParser.emitError(odsParser.getCurrentLocation(), "failed to parse LLZK_ArrayType parameter 'elementType' which is to be a `::mlir::Type`");
160 return {};
161 }
162 // Parse literal '>'
163 if (odsParser.parseGreater()) return {};
164 assert(::mlir::succeeded(_result_elementType));
165 assert(::mlir::succeeded(_result_dimensionSizes));
166 assert(::mlir::succeeded(_result_shape));
167 return odsParser.getChecked<ArrayType>(odsLoc, odsParser.getContext(),
168 ::mlir::Type((*_result_elementType)),
169 ::llvm::ArrayRef<::mlir::Attribute>((*_result_dimensionSizes)),
170 ::llvm::ArrayRef<int64_t>((*_result_shape)));
171}
172
173void ArrayType::print(::mlir::AsmPrinter &odsPrinter) const {
174 ::mlir::Builder odsBuilder(getContext());
175 odsPrinter << "<";
176 printAttrVec(odsPrinter,
178 printDerivedShape(odsPrinter,
179 getShape(),
181 odsPrinter << ' ' << "x";
182 odsPrinter << ' ';
183 odsPrinter.printStrippedAttrOrType(getElementType());
184 odsPrinter << ">";
185}
186
187::mlir::Type ArrayType::getElementType() const {
188 return getImpl()->elementType;
189}
190
191::llvm::ArrayRef<::mlir::Attribute> ArrayType::getDimensionSizes() const {
192 return getImpl()->dimensionSizes;
193}
194
195::llvm::ArrayRef<int64_t> ArrayType::getShape() const {
196 return getImpl()->shape;
197}
198
199} // namespace array
200} // namespace llzk
201MLIR_DEFINE_EXPLICIT_TYPE_ID(::llzk::array::ArrayType)
202namespace llzk {
203namespace array {
204
206::mlir::Type ArrayDialect::parseType(::mlir::DialectAsmParser &parser) const {
207 ::llvm::SMLoc typeLoc = parser.getCurrentLocation();
208 ::llvm::StringRef mnemonic;
209 ::mlir::Type genType;
210 auto parseResult = generatedTypeParser(parser, &mnemonic, genType);
211 if (parseResult.has_value())
212 return genType;
213
214 parser.emitError(typeLoc) << "unknown type `"
215 << mnemonic << "` in dialect `" << getNamespace() << "`";
216 return {};
217}
218
219void ArrayDialect::printType(::mlir::Type type,
220 ::mlir::DialectAsmPrinter &printer) const {
221 if (::mlir::succeeded(generatedTypePrinter(type, printer)))
222 return;
223
224}
225} // namespace array
226} // namespace llzk
227
228#endif // GET_TYPEDEF_CLASSES
229
::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:58
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:93
::llvm::ArrayRef<::mlir::Attribute > getDimensionSizes() const
ParseResult parseAttrVec(AsmParser &parser, SmallVector< Attribute > &value)
Definition Types.cpp:146
void printDerivedShape(AsmPrinter &, ArrayRef< int64_t >, ArrayRef< Attribute >)
Definition Types.cpp:72
LogicalResult computeDimsFromShape(MLIRContext *ctx, ArrayRef< int64_t > shape, SmallVector< Attribute > &dimensionSizes)
Definition Types.cpp:19
void printAttrVec(AsmPrinter &printer, ArrayRef< Attribute > value)
Definition Types.cpp:167
LogicalResult computeShapeFromDims(EmitErrorFn emitError, MLIRContext *ctx, ArrayRef< Attribute > dimensionSizes, SmallVector< int64_t > &shape)
Definition Types.cpp:30
ParseResult parseDerivedShape(AsmParser &parser, SmallVector< int64_t > &shape, SmallVector< Attribute > dimensionSizes)
Definition Types.cpp:64
SmallVector< Attribute > forceIntAttrTypes(ArrayRef< Attribute > attrList)
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