MLIR  18.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"
23 #include "llvm/ADT/STLExtras.h"
24 #include "llvm/ADT/Twine.h"
25 
26 namespace mlir {
27 //===--------------------------------------------------------------------===//
28 // Dialect Version Interface.
29 //===--------------------------------------------------------------------===//
30 
31 /// This class is used to represent the version of a dialect, for the purpose
32 /// of polymorphic destruction.
34 public:
35  virtual ~DialectVersion() = default;
36 };
37 
38 //===----------------------------------------------------------------------===//
39 // DialectBytecodeReader
40 //===----------------------------------------------------------------------===//
41 
42 /// This class defines a virtual interface for reading a bytecode stream,
43 /// providing hooks into the bytecode reader. As such, this class should only be
44 /// derived and defined by the main bytecode reader, users (i.e. dialects)
45 /// should generally only interact with this class via the
46 /// BytecodeDialectInterface below.
48 public:
49  virtual ~DialectBytecodeReader() = default;
50 
51  /// Emit an error to the reader.
52  virtual InFlightDiagnostic emitError(const Twine &msg = {}) const = 0;
53 
54  /// Retrieve the dialect version by name if available.
56  getDialectVersion(StringRef dialectName) const = 0;
57 
58  /// Retrieve the context associated to the reader.
59  virtual MLIRContext *getContext() const = 0;
60 
61  /// Return the bytecode version being read.
62  virtual uint64_t getBytecodeVersion() const = 0;
63 
64  /// Read out a list of elements, invoking the provided callback for each
65  /// element. The callback function may be in any of the following forms:
66  /// * LogicalResult(T &)
67  /// * FailureOr<T>()
68  template <typename T, typename CallbackFn>
69  LogicalResult readList(SmallVectorImpl<T> &result, CallbackFn &&callback) {
70  uint64_t size;
71  if (failed(readVarInt(size)))
72  return failure();
73  result.reserve(size);
74 
75  for (uint64_t i = 0; i < size; ++i) {
76  // Check if the callback uses FailureOr, or populates the result by
77  // reference.
78  if constexpr (llvm::function_traits<std::decay_t<CallbackFn>>::num_args) {
79  T element = {};
80  if (failed(callback(element)))
81  return failure();
82  result.emplace_back(std::move(element));
83  } else {
84  FailureOr<T> element = callback();
85  if (failed(element))
86  return failure();
87  result.emplace_back(std::move(*element));
88  }
89  }
90  return success();
91  }
92 
93  //===--------------------------------------------------------------------===//
94  // IR
95  //===--------------------------------------------------------------------===//
96 
97  /// Read a reference to the given attribute.
98  virtual LogicalResult readAttribute(Attribute &result) = 0;
99  /// Read an optional reference to the given attribute. Returns success even if
100  /// the Attribute isn't present.
102 
103  template <typename T>
105  return readList(attrs, [this](T &attr) { return readAttribute(attr); });
106  }
107  template <typename T>
109  Attribute baseResult;
110  if (failed(readAttribute(baseResult)))
111  return failure();
112  if ((result = dyn_cast<T>(baseResult)))
113  return success();
114  return emitError() << "expected " << llvm::getTypeName<T>()
115  << ", but got: " << baseResult;
116  }
117  template <typename T>
119  Attribute baseResult;
120  if (failed(readOptionalAttribute(baseResult)))
121  return failure();
122  if (!baseResult)
123  return success();
124  if ((result = dyn_cast<T>(baseResult)))
125  return success();
126  return emitError() << "expected " << llvm::getTypeName<T>()
127  << ", but got: " << baseResult;
128  }
129 
130  /// Read a reference to the given type.
131  virtual LogicalResult readType(Type &result) = 0;
132  template <typename T>
134  return readList(types, [this](T &type) { return readType(type); });
135  }
136  template <typename T>
137  LogicalResult readType(T &result) {
138  Type baseResult;
139  if (failed(readType(baseResult)))
140  return failure();
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 handle to a dialect resource.
148  template <typename ResourceT>
151  if (failed(handle))
152  return failure();
153  if (auto *result = dyn_cast<ResourceT>(&*handle))
154  return std::move(*result);
155  return emitError() << "provided resource handle differs from the "
156  "expected resource type";
157  }
158 
159  //===--------------------------------------------------------------------===//
160  // Primitives
161  //===--------------------------------------------------------------------===//
162 
163  /// Read a variable width integer.
164  virtual LogicalResult readVarInt(uint64_t &result) = 0;
165 
166  /// Read a signed variable width integer.
167  virtual LogicalResult readSignedVarInt(int64_t &result) = 0;
169  return readList(result,
170  [this](int64_t &value) { return readSignedVarInt(value); });
171  }
172 
173  /// Parse a variable length encoded integer whose low bit is used to encode an
174  /// unrelated flag, i.e: `(integerValue << 1) | (flag ? 1 : 0)`.
175  LogicalResult readVarIntWithFlag(uint64_t &result, bool &flag) {
176  if (failed(readVarInt(result)))
177  return failure();
178  flag = result & 1;
179  result >>= 1;
180  return success();
181  }
182 
183  /// Read a "small" sparse array of integer <= 32 bits elements, where
184  /// index/value pairs can be compressed when the array is small.
185  /// Note that only some position of the array will be read and the ones
186  /// not stored in the bytecode are gonne be left untouched.
187  /// If the provided array is too small for the stored indices, an error
188  /// will be returned.
189  template <typename T>
191  static_assert(sizeof(T) < sizeof(uint64_t), "expect integer < 64 bits");
192  static_assert(std::is_integral<T>::value, "expects integer");
193  uint64_t nonZeroesCount;
194  bool useSparseEncoding;
195  if (failed(readVarIntWithFlag(nonZeroesCount, useSparseEncoding)))
196  return failure();
197  if (nonZeroesCount == 0)
198  return success();
199  if (!useSparseEncoding) {
200  // This is a simple dense array.
201  if (nonZeroesCount > array.size()) {
202  emitError("trying to read an array of ")
203  << nonZeroesCount << " but only " << array.size()
204  << " storage available.";
205  return failure();
206  }
207  for (int64_t index : llvm::seq<int64_t>(0, nonZeroesCount)) {
208  uint64_t value;
209  if (failed(readVarInt(value)))
210  return failure();
211  array[index] = value;
212  }
213  return success();
214  }
215  // Read sparse encoding
216  // This is the number of bits used for packing the index with the value.
217  uint64_t indexBitSize;
218  if (failed(readVarInt(indexBitSize)))
219  return failure();
220  constexpr uint64_t maxIndexBitSize = 8;
221  if (indexBitSize > maxIndexBitSize) {
222  emitError("reading sparse array with indexing above 8 bits: ")
223  << indexBitSize;
224  return failure();
225  }
226  for (uint32_t count : llvm::seq<uint32_t>(0, nonZeroesCount)) {
227  (void)count;
228  uint64_t indexValuePair;
229  if (failed(readVarInt(indexValuePair)))
230  return failure();
231  uint64_t index = indexValuePair & ~(uint64_t(-1) << (indexBitSize));
232  uint64_t value = indexValuePair >> indexBitSize;
233  if (index >= array.size()) {
234  emitError("reading a sparse array found index ")
235  << index << " but only " << array.size() << " storage available.";
236  return failure();
237  }
238  array[index] = value;
239  }
240  return success();
241  }
242 
243  /// Read an APInt that is known to have been encoded with the given width.
244  virtual FailureOr<APInt> readAPIntWithKnownWidth(unsigned bitWidth) = 0;
245 
246  /// Read an APFloat that is known to have been encoded with the given
247  /// semantics.
248  virtual FailureOr<APFloat>
249  readAPFloatWithKnownSemantics(const llvm::fltSemantics &semantics) = 0;
250 
251  /// Read a string from the bytecode.
252  virtual LogicalResult readString(StringRef &result) = 0;
253 
254  /// Read a blob from the bytecode.
255  virtual LogicalResult readBlob(ArrayRef<char> &result) = 0;
256 
257  /// Read a bool from the bytecode.
258  virtual LogicalResult readBool(bool &result) = 0;
259 
260 private:
261  /// Read a handle to a dialect resource.
263 };
264 
265 //===----------------------------------------------------------------------===//
266 // DialectBytecodeWriter
267 //===----------------------------------------------------------------------===//
268 
269 /// This class defines a virtual interface for writing to a bytecode stream,
270 /// providing hooks into the bytecode writer. As such, this class should only be
271 /// derived and defined by the main bytecode writer, users (i.e. dialects)
272 /// should generally only interact with this class via the
273 /// BytecodeDialectInterface below.
275 public:
276  virtual ~DialectBytecodeWriter() = default;
277 
278  //===--------------------------------------------------------------------===//
279  // IR
280  //===--------------------------------------------------------------------===//
281 
282  /// Write out a list of elements, invoking the provided callback for each
283  /// element.
284  template <typename RangeT, typename CallbackFn>
285  void writeList(RangeT &&range, CallbackFn &&callback) {
286  writeVarInt(llvm::size(range));
287  for (auto &element : range)
288  callback(element);
289  }
290 
291  /// Write a reference to the given attribute.
292  virtual void writeAttribute(Attribute attr) = 0;
293  virtual void writeOptionalAttribute(Attribute attr) = 0;
294  template <typename T>
296  writeList(attrs, [this](T attr) { writeAttribute(attr); });
297  }
298 
299  /// Write a reference to the given type.
300  virtual void writeType(Type type) = 0;
301  template <typename T>
302  void writeTypes(ArrayRef<T> types) {
303  writeList(types, [this](T type) { writeType(type); });
304  }
305 
306  /// Write the given handle to a dialect resource.
307  virtual void
309 
310  //===--------------------------------------------------------------------===//
311  // Primitives
312  //===--------------------------------------------------------------------===//
313 
314  /// Write a variable width integer to the output stream. This should be the
315  /// preferred method for emitting integers whenever possible.
316  virtual void writeVarInt(uint64_t value) = 0;
317 
318  /// Write a signed variable width integer to the output stream. This should be
319  /// the preferred method for emitting signed integers whenever possible.
320  virtual void writeSignedVarInt(int64_t value) = 0;
322  writeList(value, [this](int64_t value) { writeSignedVarInt(value); });
323  }
324 
325  /// Write a VarInt and a flag packed together.
326  void writeVarIntWithFlag(uint64_t value, bool flag) {
327  writeVarInt((value << 1) | (flag ? 1 : 0));
328  }
329 
330  /// Write out a "small" sparse array of integer <= 32 bits elements, where
331  /// index/value pairs can be compressed when the array is small. This method
332  /// will scan the array multiple times and should not be used for large
333  /// arrays. The optional provided "zero" can be used to adjust for the
334  /// expected repeated value. We assume here that the array size fits in a 32
335  /// bits integer.
336  template <typename T>
338  static_assert(sizeof(T) < sizeof(uint64_t), "expect integer < 64 bits");
339  static_assert(std::is_integral<T>::value, "expects integer");
340  uint32_t size = array.size();
341  uint32_t nonZeroesCount = 0, lastIndex = 0;
342  for (uint32_t index : llvm::seq<uint32_t>(0, size)) {
343  if (!array[index])
344  continue;
345  nonZeroesCount++;
346  lastIndex = index;
347  }
348  // If the last position is too large, or the array isn't at least 50%
349  // sparse, emit it with a dense encoding.
350  if (lastIndex > 256 || nonZeroesCount > size / 2) {
351  // Emit the array size and a flag which indicates whether it is sparse.
352  writeVarIntWithFlag(size, false);
353  for (const T &elt : array)
354  writeVarInt(elt);
355  return;
356  }
357  // Emit sparse: first the number of elements we'll write and a flag
358  // indicating it is a sparse encoding.
359  writeVarIntWithFlag(nonZeroesCount, true);
360  if (nonZeroesCount == 0)
361  return;
362  // This is the number of bits used for packing the index with the value.
363  int indexBitSize = llvm::Log2_32_Ceil(lastIndex + 1);
364  writeVarInt(indexBitSize);
365  for (uint32_t index : llvm::seq<uint32_t>(0, lastIndex + 1)) {
366  T value = array[index];
367  if (!value)
368  continue;
369  uint64_t indexValuePair = (value << indexBitSize) | (index);
370  writeVarInt(indexValuePair);
371  }
372  }
373 
374  /// Write an APInt to the bytecode stream whose bitwidth will be known
375  /// externally at read time. This method is useful for encoding APInt values
376  /// when the width is known via external means, such as via a type. This
377  /// method should generally only be invoked if you need an APInt, otherwise
378  /// use the varint methods above. APInt values are generally encoded using
379  /// zigzag encoding, to enable more efficient encodings for negative values.
380  virtual void writeAPIntWithKnownWidth(const APInt &value) = 0;
381 
382  /// Write an APFloat to the bytecode stream whose semantics will be known
383  /// externally at read time. This method is useful for encoding APFloat values
384  /// when the semantics are known via external means, such as via a type.
385  virtual void writeAPFloatWithKnownSemantics(const APFloat &value) = 0;
386 
387  /// Write a string to the bytecode, which is owned by the caller and is
388  /// guaranteed to not die before the end of the bytecode process. This should
389  /// only be called if such a guarantee can be made, such as when the string is
390  /// owned by an attribute or type.
391  virtual void writeOwnedString(StringRef str) = 0;
392 
393  /// Write a blob to the bytecode, which is owned by the caller and is
394  /// guaranteed to not die before the end of the bytecode process. The blob is
395  /// written as-is, with no additional compression or compaction.
396  virtual void writeOwnedBlob(ArrayRef<char> blob) = 0;
397 
398  /// Write a bool to the output stream.
399  virtual void writeOwnedBool(bool value) = 0;
400 
401  /// Return the bytecode version being emitted for.
402  virtual int64_t getBytecodeVersion() const = 0;
403 };
404 
405 //===----------------------------------------------------------------------===//
406 // BytecodeDialectInterface
407 //===----------------------------------------------------------------------===//
408 
410  : public DialectInterface::Base<BytecodeDialectInterface> {
411 public:
412  using Base::Base;
413 
414  //===--------------------------------------------------------------------===//
415  // Reading
416  //===--------------------------------------------------------------------===//
417 
418  /// Read an attribute belonging to this dialect from the given reader. This
419  /// method should return null in the case of failure. Optionally, the dialect
420  /// version can be accessed through the reader.
422  reader.emitError() << "dialect " << getDialect()->getNamespace()
423  << " does not support reading attributes from bytecode";
424  return Attribute();
425  }
426 
427  /// Read a type belonging to this dialect from the given reader. This method
428  /// should return null in the case of failure. Optionally, the dialect version
429  /// can be accessed thorugh the reader.
430  virtual Type readType(DialectBytecodeReader &reader) const {
431  reader.emitError() << "dialect " << getDialect()->getNamespace()
432  << " does not support reading types from bytecode";
433  return Type();
434  }
435 
436  //===--------------------------------------------------------------------===//
437  // Writing
438  //===--------------------------------------------------------------------===//
439 
440  /// Write the given attribute, which belongs to this dialect, to the given
441  /// writer. This method may return failure to indicate that the given
442  /// attribute could not be encoded, in which case the textual format will be
443  /// used to encode this attribute instead.
445  DialectBytecodeWriter &writer) const {
446  return failure();
447  }
448 
449  /// Write the given type, which belongs to this dialect, to the given writer.
450  /// This method may return failure to indicate that the given type could not
451  /// be encoded, in which case the textual format will be used to encode this
452  /// type instead.
454  DialectBytecodeWriter &writer) const {
455  return failure();
456  }
457 
458  /// Write the version of this dialect to the given writer.
459  virtual void writeVersion(DialectBytecodeWriter &writer) const {}
460 
461  // Read the version of this dialect from the provided reader and return it as
462  // a `unique_ptr` to a dialect version object.
463  virtual std::unique_ptr<DialectVersion>
465  reader.emitError("Dialect does not support versioning");
466  return nullptr;
467  }
468 
469  /// Hook invoked after parsing completed, if a version directive was present
470  /// and included an entry for the current dialect. This hook offers the
471  /// opportunity to the dialect to visit the IR and upgrades constructs emitted
472  /// by the version of the dialect corresponding to the provided version.
473  virtual LogicalResult
475  const DialectVersion &version) const {
476  return success();
477  }
478 };
479 
480 /// Helper for resource handle reading that returns LogicalResult.
481 template <typename T, typename... Ts>
483  FailureOr<T> &value, Ts &&...params) {
484  FailureOr<T> handle = reader.readResourceHandle<T>();
485  if (failed(handle))
486  return failure();
487  if (auto *result = dyn_cast<T>(&*handle)) {
488  value = std::move(*result);
489  return success();
490  }
491  return failure();
492 }
493 
494 /// Helper method that injects context only if needed, this helps unify some of
495 /// the attribute construction methods.
496 template <typename T, typename... Ts>
497 auto get(MLIRContext *context, Ts &&...params) {
498  // Prefer a direct `get` method if one exists.
499  if constexpr (llvm::is_detected<detail::has_get_method, T, Ts...>::value) {
500  (void)context;
501  return T::get(std::forward<Ts>(params)...);
502  } else if constexpr (llvm::is_detected<detail::has_get_method, T,
503  MLIRContext *, Ts...>::value) {
504  return T::get(context, std::forward<Ts>(params)...);
505  } else {
506  // Otherwise, pass to the base get.
507  return T::Base::get(context, std::forward<Ts>(params)...);
508  }
509 }
510 
511 } // namespace mlir
512 
513 #endif // MLIR_BYTECODE_BYTECODEIMPLEMENTATION_H
This class represents an opaque handle to a dialect resource entry.
Attributes are known-constant values of operations.
Definition: Attributes.h:25
virtual Type readType(DialectBytecodeReader &reader) const
Read a type belonging to this dialect from the given reader.
virtual LogicalResult upgradeFromVersion(Operation *topLevelOp, const DialectVersion &version) const
Hook invoked after parsing completed, if a version directive was present and included an entry for th...
virtual Attribute readAttribute(DialectBytecodeReader &reader) const
Read an attribute belonging to this dialect from the given reader.
virtual std::unique_ptr< DialectVersion > readVersion(DialectBytecodeReader &reader) const
virtual LogicalResult writeAttribute(Attribute attr, DialectBytecodeWriter &writer) const
Write the given attribute, which belongs to this dialect, to the given writer.
virtual LogicalResult writeType(Type type, DialectBytecodeWriter &writer) const
Write the given type, which belongs to this dialect, to the given writer.
virtual void writeVersion(DialectBytecodeWriter &writer) const
Write the version of this dialect to the given writer.
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)
FailureOr< ResourceT > readResourceHandle()
Read a handle to a dialect resource.
virtual MLIRContext * getContext() const =0
Retrieve the context associated to the reader.
virtual FailureOr< APInt > readAPIntWithKnownWidth(unsigned bitWidth)=0
Read an APInt that is known to have been encoded with the given width.
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 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,...
LogicalResult readSignedVarInts(SmallVectorImpl< int64_t > &result)
LogicalResult readOptionalAttribute(T &result)
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...
virtual FailureOr< APFloat > readAPFloatWithKnownSemantics(const llvm::fltSemantics &semantics)=0
Read an APFloat that is known to have been encoded with the given semantics.
virtual FailureOr< const DialectVersion * > getDialectVersion(StringRef dialectName) const =0
Retrieve the dialect version by name if available.
virtual LogicalResult readString(StringRef &result)=0
Read a string from the bytecode.
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.
This class defines a virtual interface for writing to a bytecode stream, providing hooks into the byt...
virtual void writeOptionalAttribute(Attribute attr)=0
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 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 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 provides support for representing a failure result, or a valid value of type T.
Definition: LogicalResult.h:78
This class represents a diagnostic that is inflight and set to be reported.
Definition: Diagnostics.h:308
MLIRContext is the top-level object for a collection of MLIR operations.
Definition: MLIRContext.h:60
Operation is the basic unit of execution within MLIR.
Definition: Operation.h:88
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition: Types.h:74
The base class used for all derived interface types.
decltype(T::get(std::declval< Ts >()...)) has_get_method
This header declares functions that assist transformations in the MemRef dialect.
LogicalResult failure(bool isFailure=true)
Utility function to generate a LogicalResult.
Definition: LogicalResult.h:62
static LogicalResult readResourceHandle(DialectBytecodeReader &reader, FailureOr< T > &value, Ts &&...params)
Helper for resource handle reading that returns LogicalResult.
LogicalResult success(bool isSuccess=true)
Utility function to generate a LogicalResult.
Definition: LogicalResult.h:56
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
bool failed(LogicalResult result)
Utility function that returns true if the provided LogicalResult corresponds to a failure value.
Definition: LogicalResult.h:72
This class represents an efficient way to signal success or failure.
Definition: LogicalResult.h:26