MLIR 24.0.0git
BytecodeImplementation.h
Go to the documentation of this file.
1//===- BytecodeImplementation.h - MLIR Bytecode Implementation --*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This header defines various interfaces and utilities necessary for dialects
10// to hook into bytecode serialization.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef MLIR_BYTECODE_BYTECODEIMPLEMENTATION_H
15#define MLIR_BYTECODE_BYTECODEIMPLEMENTATION_H
16
17#include "mlir/IR/Attributes.h"
18#include "mlir/IR/Diagnostics.h"
19#include "mlir/IR/Dialect.h"
21#include "llvm/ADT/STLExtras.h"
22#include "llvm/ADT/Twine.h"
23
24namespace mlir {
25//===--------------------------------------------------------------------===//
26// Dialect Version Interface.
27//===--------------------------------------------------------------------===//
28
29/// This class is used to represent the version of a dialect, for the purpose
30/// of polymorphic destruction.
32public:
33 virtual ~DialectVersion() = default;
34};
35
36//===----------------------------------------------------------------------===//
37// DialectBytecodeReader
38//===----------------------------------------------------------------------===//
39
40/// This class defines a virtual interface for reading a bytecode stream,
41/// providing hooks into the bytecode reader. As such, this class should only be
42/// derived and defined by the main bytecode reader, users (i.e. dialects)
43/// should generally only interact with this class via the
44/// BytecodeDialectInterface below.
46public:
47 virtual ~DialectBytecodeReader() = default;
48
49 /// Emit an error to the reader.
50 virtual InFlightDiagnostic emitError(const Twine &msg = {}) const = 0;
51
52 /// Emit a warning to the reader.
53 virtual InFlightDiagnostic emitWarning(const Twine &msg = {}) const = 0;
54
55 /// Retrieve the dialect version by name if available.
56 virtual FailureOr<const DialectVersion *>
57 getDialectVersion(StringRef dialectName) const = 0;
58 template <class T>
59 FailureOr<const DialectVersion *> getDialectVersion() const {
60 return getDialectVersion(T::getDialectNamespace());
61 }
62
63 /// Retrieve the context associated to the reader.
64 virtual MLIRContext *getContext() const = 0;
65
66 /// Return the bytecode version being read.
67 virtual uint64_t getBytecodeVersion() const = 0;
68
69 /// Read out a list of elements, invoking the provided callback for each
70 /// element. The callback function may be in any of the following forms:
71 /// * LogicalResult(T &)
72 /// * FailureOr<T>()
73 template <typename T, typename CallbackFn>
74 LogicalResult readList(SmallVectorImpl<T> &result, CallbackFn &&callback) {
75 uint64_t size;
76 if (failed(readVarInt(size)))
77 return failure();
78 return readListWithKnownSize(result, size,
79 std::forward<CallbackFn>(callback));
80 }
81
82 /// Read out a list of elements with a known size, invoking the provided
83 /// callback for each element. Unlike readList, this does not read a length
84 /// prefix. The callback function may be in any of the following forms:
85 /// * LogicalResult(T &)
86 /// * FailureOr<T>()
87 template <typename T, typename CallbackFn>
88 LogicalResult readListWithKnownSize(SmallVectorImpl<T> &result, uint64_t size,
89 CallbackFn &&callback) {
90 result.reserve(size);
91
92 for (uint64_t i = 0; i < size; ++i) {
93 // Check if the callback uses FailureOr, or populates the result by
94 // reference.
95 if constexpr (llvm::function_traits<std::decay_t<CallbackFn>>::num_args) {
96 T element = {};
97 if (failed(callback(element)))
98 return failure();
99 result.emplace_back(std::move(element));
100 } else {
101 FailureOr<T> element = callback();
102 if (failed(element))
103 return failure();
104 result.emplace_back(std::move(*element));
105 }
106 }
107 return success();
108 }
109
110 //===--------------------------------------------------------------------===//
111 // IR
112 //===--------------------------------------------------------------------===//
113
114 /// Read a reference to the given attribute.
115 virtual LogicalResult readAttribute(Attribute &result) = 0;
116 /// Read an optional reference to the given attribute. Returns success even if
117 /// the Attribute isn't present.
118 virtual LogicalResult readOptionalAttribute(Attribute &attr) = 0;
119
120 template <typename T>
121 LogicalResult readAttributes(SmallVectorImpl<T> &attrs) {
122 return readList(attrs, [this](T &attr) { return readAttribute(attr); });
123 }
124 template <typename T>
125 LogicalResult readAttribute(T &result) {
126 Attribute baseResult;
127 if (failed(readAttribute(baseResult)))
128 return failure();
129 if ((result = dyn_cast<T>(baseResult)))
130 return success();
131 return emitError() << "expected " << llvm::getTypeName<T>()
132 << ", but got: " << baseResult;
133 }
134 template <typename T>
135 LogicalResult readOptionalAttribute(T &result) {
136 Attribute baseResult;
137 if (failed(readOptionalAttribute(baseResult)))
138 return failure();
139 if (!baseResult)
140 return success();
141 if ((result = dyn_cast<T>(baseResult)))
142 return success();
143 return emitError() << "expected " << llvm::getTypeName<T>()
144 << ", but got: " << baseResult;
145 }
146
147 /// Read a reference to the given type.
148 virtual LogicalResult readType(Type &result) = 0;
149 template <typename T>
150 LogicalResult readTypes(SmallVectorImpl<T> &types) {
151 return readList(types, [this](T &type) { return readType(type); });
152 }
153 template <typename T>
154 LogicalResult readType(T &result) {
155 Type baseResult;
156 if (failed(readType(baseResult)))
157 return failure();
158 if ((result = dyn_cast<T>(baseResult)))
159 return success();
160 return emitError() << "expected " << llvm::getTypeName<T>()
161 << ", but got: " << baseResult;
162 }
163
164 /// Read a handle to a dialect resource.
165 template <typename ResourceT>
166 FailureOr<ResourceT> readResourceHandle() {
167 FailureOr<AsmDialectResourceHandle> handle = readResourceHandle();
168 if (failed(handle))
169 return failure();
170 if (auto *result = dyn_cast<ResourceT>(&*handle))
171 return std::move(*result);
172 return emitError() << "provided resource handle differs from the "
173 "expected resource type";
174 }
175
176 //===--------------------------------------------------------------------===//
177 // Primitives
178 //===--------------------------------------------------------------------===//
179
180 /// Read a variable width integer.
181 virtual LogicalResult readVarInt(uint64_t &result) = 0;
182
183 /// Read a signed variable width integer.
184 virtual LogicalResult readSignedVarInt(int64_t &result) = 0;
186 return readList(result,
187 [this](int64_t &value) { return readSignedVarInt(value); });
188 }
189
190 /// Parse a variable length encoded integer whose low bit is used to encode an
191 /// unrelated flag, i.e: `(integerValue << 1) | (flag ? 1 : 0)`.
192 LogicalResult readVarIntWithFlag(uint64_t &result, bool &flag) {
193 if (failed(readVarInt(result)))
194 return failure();
195 flag = result & 1;
196 result >>= 1;
197 return success();
198 }
199
200 /// Read a "small" sparse array of integer <= 32 bits elements, where
201 /// index/value pairs can be compressed when the array is small.
202 /// Note that only some position of the array will be read and the ones
203 /// not stored in the bytecode are gonne be left untouched.
204 /// If the provided array is too small for the stored indices, an error
205 /// will be returned.
206 template <typename T>
207 LogicalResult readSparseArray(MutableArrayRef<T> array) {
208 static_assert(sizeof(T) < sizeof(uint64_t), "expect integer < 64 bits");
209 static_assert(std::is_integral<T>::value, "expects integer");
210 uint64_t nonZeroesCount;
211 bool useSparseEncoding;
212 if (failed(readVarIntWithFlag(nonZeroesCount, useSparseEncoding)))
213 return failure();
214 if (nonZeroesCount == 0)
215 return success();
216 if (!useSparseEncoding) {
217 // This is a simple dense array.
218 if (nonZeroesCount > array.size()) {
219 emitError("trying to read an array of ")
220 << nonZeroesCount << " but only " << array.size()
221 << " storage available.";
222 return failure();
223 }
224 for (int64_t index : llvm::seq<int64_t>(0, nonZeroesCount)) {
225 uint64_t value;
226 if (failed(readVarInt(value)))
227 return failure();
228 array[index] = value;
229 }
230 return success();
231 }
232 // Read sparse encoding
233 // This is the number of bits used for packing the index with the value.
234 uint64_t indexBitSize;
235 if (failed(readVarInt(indexBitSize)))
236 return failure();
237 constexpr uint64_t maxIndexBitSize = 8;
238 if (indexBitSize > maxIndexBitSize) {
239 emitError("reading sparse array with indexing above 8 bits: ")
240 << indexBitSize;
241 return failure();
242 }
243 for (uint32_t count : llvm::seq<uint32_t>(0, nonZeroesCount)) {
244 (void)count;
245 uint64_t indexValuePair;
246 if (failed(readVarInt(indexValuePair)))
247 return failure();
248 uint64_t index = indexValuePair & ~(uint64_t(-1) << (indexBitSize));
249 uint64_t value = indexValuePair >> indexBitSize;
250 if (index >= array.size()) {
251 emitError("reading a sparse array found index ")
252 << index << " but only " << array.size() << " storage available.";
253 return failure();
254 }
255 array[index] = value;
256 }
257 return success();
258 }
259
260 /// Read an APInt that is known to have been encoded with the given width.
261 virtual FailureOr<APInt> readAPIntWithKnownWidth(unsigned bitWidth) = 0;
262
263 /// Read an APFloat that is known to have been encoded with the given
264 /// semantics.
265 virtual FailureOr<APFloat>
266 readAPFloatWithKnownSemantics(const llvm::fltSemantics &semantics) = 0;
267
268 /// Read a string from the bytecode.
269 virtual LogicalResult readString(StringRef &result) = 0;
270
271 /// Read a blob from the bytecode.
272 virtual LogicalResult readBlob(ArrayRef<char> &result) = 0;
273
274 /// Read a bool from the bytecode.
275 virtual LogicalResult readBool(bool &result) = 0;
276
277private:
278 /// Read a handle to a dialect resource.
279 virtual FailureOr<AsmDialectResourceHandle> readResourceHandle() = 0;
280};
281
282//===----------------------------------------------------------------------===//
283// DialectBytecodeWriter
284//===----------------------------------------------------------------------===//
285
286/// This class defines a virtual interface for writing to a bytecode stream,
287/// providing hooks into the bytecode writer. As such, this class should only be
288/// derived and defined by the main bytecode writer, users (i.e. dialects)
289/// should generally only interact with this class via the
290/// BytecodeDialectInterface below.
292public:
293 virtual ~DialectBytecodeWriter() = default;
294
295 //===--------------------------------------------------------------------===//
296 // IR
297 //===--------------------------------------------------------------------===//
298
299 /// Write out a list of elements, invoking the provided callback for each
300 /// element.
301 template <typename RangeT, typename CallbackFn>
302 void writeList(RangeT &&range, CallbackFn &&callback) {
303 writeVarInt(llvm::size(range));
304 for (auto &element : range)
305 callback(element);
306 }
307
308 /// Write out a list of elements without a length prefix, for cases where the
309 /// size is known from another field.
310 template <typename RangeT, typename CallbackFn>
311 void writeListWithKnownSize(RangeT &&range, CallbackFn &&callback) {
312 for (auto &element : range)
313 callback(element);
314 }
315
316 /// Write a reference to the given attribute.
317 virtual void writeAttribute(Attribute attr) = 0;
318 virtual void writeOptionalAttribute(Attribute attr) = 0;
319 template <typename T>
321 writeList(attrs, [this](T attr) { writeAttribute(attr); });
322 }
323
324 /// Write a reference to the given type.
325 virtual void writeType(Type type) = 0;
326 template <typename T>
328 writeList(types, [this](T type) { writeType(type); });
329 }
330
331 /// Write the given handle to a dialect resource.
332 virtual void
334
335 //===--------------------------------------------------------------------===//
336 // Primitives
337 //===--------------------------------------------------------------------===//
338
339 /// Write a variable width integer to the output stream. This should be the
340 /// preferred method for emitting integers whenever possible.
341 virtual void writeVarInt(uint64_t value) = 0;
342
343 /// Write a signed variable width integer to the output stream. This should be
344 /// the preferred method for emitting signed integers whenever possible.
345 virtual void writeSignedVarInt(int64_t value) = 0;
347 writeList(value, [this](int64_t value) { writeSignedVarInt(value); });
348 }
349
350 /// Write a VarInt and a flag packed together.
351 void writeVarIntWithFlag(uint64_t value, bool flag) {
352 writeVarInt((value << 1) | (flag ? 1 : 0));
353 }
354
355 /// Write out a "small" sparse array of integer <= 32 bits elements, where
356 /// index/value pairs can be compressed when the array is small. This method
357 /// will scan the array multiple times and should not be used for large
358 /// arrays. The optional provided "zero" can be used to adjust for the
359 /// expected repeated value. We assume here that the array size fits in a 32
360 /// bits integer.
361 template <typename T>
363 static_assert(sizeof(T) < sizeof(uint64_t), "expect integer < 64 bits");
364 static_assert(std::is_integral<T>::value, "expects integer");
365 uint32_t size = array.size();
366 uint32_t nonZeroesCount = 0, lastIndex = 0;
367 for (uint32_t index : llvm::seq<uint32_t>(0, size)) {
368 if (!array[index])
369 continue;
370 nonZeroesCount++;
371 lastIndex = index;
372 }
373 // If the last position is too large, or the array isn't at least 50%
374 // sparse, emit it with a dense encoding.
375 if (lastIndex > 256 || nonZeroesCount > size / 2) {
376 // Emit the array size and a flag which indicates whether it is sparse.
377 writeVarIntWithFlag(size, false);
378 for (const T &elt : array)
379 writeVarInt(elt);
380 return;
381 }
382 // Emit sparse: first the number of elements we'll write and a flag
383 // indicating it is a sparse encoding.
384 writeVarIntWithFlag(nonZeroesCount, true);
385 if (nonZeroesCount == 0)
386 return;
387 // This is the number of bits used for packing the index with the value.
388 int indexBitSize = llvm::Log2_32_Ceil(lastIndex + 1);
389 writeVarInt(indexBitSize);
390 for (uint32_t index : llvm::seq<uint32_t>(0, lastIndex + 1)) {
391 T value = array[index];
392 if (!value)
393 continue;
394 uint64_t indexValuePair = (value << indexBitSize) | (index);
395 writeVarInt(indexValuePair);
396 }
397 }
398
399 /// Write an APInt to the bytecode stream whose bitwidth will be known
400 /// externally at read time. This method is useful for encoding APInt values
401 /// when the width is known via external means, such as via a type. This
402 /// method should generally only be invoked if you need an APInt, otherwise
403 /// use the varint methods above. APInt values are generally encoded using
404 /// zigzag encoding, to enable more efficient encodings for negative values.
405 virtual void writeAPIntWithKnownWidth(const APInt &value) = 0;
406
407 /// Write an APFloat to the bytecode stream whose semantics will be known
408 /// externally at read time. This method is useful for encoding APFloat values
409 /// when the semantics are known via external means, such as via a type.
410 virtual void writeAPFloatWithKnownSemantics(const APFloat &value) = 0;
411
412 /// Write a string to the bytecode, which is owned by the caller and is
413 /// guaranteed to not die before the end of the bytecode process. This should
414 /// only be called if such a guarantee can be made, such as when the string is
415 /// owned by an attribute or type.
416 virtual void writeOwnedString(StringRef str) = 0;
417
418 /// Write a blob to the bytecode, which is owned by the caller and is
419 /// guaranteed to not die before the end of the bytecode process. The blob is
420 /// written as-is, with no additional compression or compaction.
421 virtual void writeOwnedBlob(ArrayRef<char> blob) = 0;
422
423 /// Write a blob to the bytecode, which is not owned by the caller. The blob
424 /// is copied into the bytecode, and need not strictly outlive the call.
425 virtual void writeUnownedBlob(ArrayRef<char> blob) = 0;
426
427 /// Write a bool to the output stream.
428 virtual void writeOwnedBool(bool value) = 0;
429
430 /// Return the bytecode version being emitted for.
431 virtual int64_t getBytecodeVersion() const = 0;
432
433 /// Retrieve the dialect version by name if available.
434 virtual FailureOr<const DialectVersion *>
435 getDialectVersion(StringRef dialectName) const = 0;
436
437 template <class T>
438 FailureOr<const DialectVersion *> getDialectVersion() const {
439 return getDialectVersion(T::getDialectNamespace());
440 }
441};
442
443/// Helper for resource handle reading that returns LogicalResult.
444template <typename T, typename... Ts>
446 FailureOr<T> &value, Ts &&...params) {
447 FailureOr<T> handle = reader.readResourceHandle<T>();
448 if (failed(handle))
449 return failure();
450 if (auto *result = dyn_cast<T>(&*handle)) {
451 value = std::move(*result);
452 return success();
453 }
454 return failure();
455}
456
457/// Helper method that injects context only if needed, this helps unify some of
458/// the attribute construction methods.
459template <typename T, typename... Ts>
460auto get(MLIRContext *context, Ts &&...params) {
461 // Prefer a direct `get` method if one exists.
462 if constexpr (llvm::is_detected<detail::has_get_method, T, Ts...>::value) {
463 (void)context;
464 return T::get(std::forward<Ts>(params)...);
465 } else if constexpr (llvm::is_detected<detail::has_get_method, T,
466 MLIRContext *, Ts...>::value) {
467 return T::get(context, std::forward<Ts>(params)...);
468 } else {
469 // Otherwise, pass to the base get.
470 return T::Base::get(context, std::forward<Ts>(params)...);
471 }
472}
473
474namespace detail {
475template <typename T, typename... Ts>
476using has_get_checked_method = decltype(T::getChecked(std::declval<Ts>()...));
477} // namespace detail
478
479/// Helper method analogous to `get`, but uses `getChecked` when available to
480/// allow graceful failure on invalid parameters instead of asserting.
481///
482/// Only the no-context form of `getChecked` is tried here. Types that expose
483/// `getChecked(emitError, params...)` without a leading `MLIRContext*` (e.g.
484/// MemRefType, VectorType, RankedTensorType) will use it for graceful failure.
485/// Everything else falls back to `get<T>()`. We intentionally do NOT try
486/// `T::getChecked(emitError, context, params...)`: for types that only inherit
487/// the base `StorageUserBase::getChecked` template (e.g. ArrayAttr), that
488/// template instantiation requires a complete storage type which may not be
489/// available in the bytecode reading TU.
490template <typename T, typename... Ts>
492 MLIRContext *context, Ts &&...params) {
493 if constexpr (llvm::is_detected<detail::has_get_checked_method, T,
495 Ts...>::value) {
496 (void)context;
497 return T::getChecked(emitError, std::forward<Ts>(params)...);
498 } else {
499 // Fall back to get() for types that don't define a no-context getChecked.
500 return get<T>(context, std::forward<Ts>(params)...);
501 }
502}
503
504} // namespace mlir
505
506#include "mlir/Bytecode/BytecodeDialectInterface.h.inc"
507
508#endif // MLIR_BYTECODE_BYTECODEIMPLEMENTATION_H
return success()
This class represents an opaque handle to a dialect resource entry.
Attributes are known-constant values of operations.
Definition Attributes.h:25
This class defines a virtual interface for reading a bytecode stream, providing hooks into the byteco...
virtual ~DialectBytecodeReader()=default
virtual LogicalResult readBlob(ArrayRef< char > &result)=0
Read a blob from the bytecode.
LogicalResult readAttributes(SmallVectorImpl< T > &attrs)
virtual MLIRContext * getContext() const =0
Retrieve the context associated to the reader.
LogicalResult readTypes(SmallVectorImpl< T > &types)
virtual LogicalResult readBool(bool &result)=0
Read a bool from the bytecode.
virtual LogicalResult readVarInt(uint64_t &result)=0
Read a variable width integer.
virtual LogicalResult readType(Type &result)=0
Read a reference to the given type.
virtual FailureOr< const DialectVersion * > getDialectVersion(StringRef dialectName) const =0
Retrieve the dialect version by name if available.
virtual uint64_t getBytecodeVersion() const =0
Return the bytecode version being read.
LogicalResult readType(T &result)
LogicalResult readVarIntWithFlag(uint64_t &result, bool &flag)
Parse a variable length encoded integer whose low bit is used to encode an unrelated flag,...
virtual FailureOr< APInt > readAPIntWithKnownWidth(unsigned bitWidth)=0
Read an APInt that is known to have been encoded with the given width.
LogicalResult readSignedVarInts(SmallVectorImpl< int64_t > &result)
LogicalResult readOptionalAttribute(T &result)
virtual InFlightDiagnostic emitWarning(const Twine &msg={}) const =0
Emit a warning to the reader.
virtual LogicalResult readOptionalAttribute(Attribute &attr)=0
Read an optional reference to the given attribute.
LogicalResult readAttribute(T &result)
virtual InFlightDiagnostic emitError(const Twine &msg={}) const =0
Emit an error to the reader.
LogicalResult readSparseArray(MutableArrayRef< T > array)
Read a "small" sparse array of integer <= 32 bits elements, where index/value pairs can be compressed...
FailureOr< ResourceT > readResourceHandle()
Read a handle to a dialect resource.
LogicalResult readListWithKnownSize(SmallVectorImpl< T > &result, uint64_t size, CallbackFn &&callback)
Read out a list of elements with a known size, invoking the provided callback for each element.
virtual LogicalResult readString(StringRef &result)=0
Read a string from the bytecode.
FailureOr< const DialectVersion * > getDialectVersion() const
virtual LogicalResult readSignedVarInt(int64_t &result)=0
Read a signed variable width integer.
LogicalResult readList(SmallVectorImpl< T > &result, CallbackFn &&callback)
Read out a list of elements, invoking the provided callback for each element.
virtual LogicalResult readAttribute(Attribute &result)=0
Read a reference to the given attribute.
virtual FailureOr< APFloat > readAPFloatWithKnownSemantics(const llvm::fltSemantics &semantics)=0
Read an APFloat that is known to have been encoded with the given semantics.
This class defines a virtual interface for writing to a bytecode stream, providing hooks into the byt...
virtual FailureOr< const DialectVersion * > getDialectVersion(StringRef dialectName) const =0
Retrieve the dialect version by name if available.
virtual void writeOptionalAttribute(Attribute attr)=0
FailureOr< const DialectVersion * > getDialectVersion() const
virtual void writeVarInt(uint64_t value)=0
Write a variable width integer to the output stream.
void writeVarIntWithFlag(uint64_t value, bool flag)
Write a VarInt and a flag packed together.
void writeList(RangeT &&range, CallbackFn &&callback)
Write out a list of elements, invoking the provided callback for each element.
void writeSparseArray(ArrayRef< T > array)
Write out a "small" sparse array of integer <= 32 bits elements, where index/value pairs can be compr...
virtual void writeType(Type type)=0
Write a reference to the given type.
virtual void writeUnownedBlob(ArrayRef< char > blob)=0
Write a blob to the bytecode, which is not owned by the caller.
virtual void writeAPIntWithKnownWidth(const APInt &value)=0
Write an APInt to the bytecode stream whose bitwidth will be known externally at read time.
virtual void writeOwnedBlob(ArrayRef< char > blob)=0
Write a blob to the bytecode, which is owned by the caller and is guaranteed to not die before the en...
virtual void writeAttribute(Attribute attr)=0
Write a reference to the given attribute.
virtual ~DialectBytecodeWriter()=default
void writeAttributes(ArrayRef< T > attrs)
virtual void writeSignedVarInt(int64_t value)=0
Write a signed variable width integer to the output stream.
virtual void writeResourceHandle(const AsmDialectResourceHandle &resource)=0
Write the given handle to a dialect resource.
virtual void writeAPFloatWithKnownSemantics(const APFloat &value)=0
Write an APFloat to the bytecode stream whose semantics will be known externally at read time.
void writeSignedVarInts(ArrayRef< int64_t > value)
virtual void writeOwnedBool(bool value)=0
Write a bool to the output stream.
virtual int64_t getBytecodeVersion() const =0
Return the bytecode version being emitted for.
virtual void writeOwnedString(StringRef str)=0
Write a string to the bytecode, which is owned by the caller and is guaranteed to not die before the ...
void writeListWithKnownSize(RangeT &&range, CallbackFn &&callback)
Write out a list of elements without a length prefix, for cases where the size is known from another ...
void writeTypes(ArrayRef< T > types)
This class is used to represent the version of a dialect, for the purpose of polymorphic destruction.
virtual ~DialectVersion()=default
This class represents a diagnostic that is inflight and set to be reported.
MLIRContext is the top-level object for a collection of MLIR operations.
Definition MLIRContext.h:71
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition Types.h:74
decltype(T::get(std::declval< Ts >()...)) has_get_method
decltype(T::getChecked(std::declval< Ts >()...)) has_get_checked_method
Include the generated interface declarations.
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
auto getChecked(function_ref< InFlightDiagnostic()> emitError, MLIRContext *context, Ts &&...params)
Helper method analogous to get, but uses getChecked when available to allow graceful failure on inval...
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
llvm::function_ref< Fn > function_ref
Definition LLVM.h:155
LogicalResult readResourceHandle(DialectBytecodeReader &reader, FailureOr< T > &value, Ts &&...params)
Helper for resource handle reading that returns LogicalResult.