MLIR 22.0.0git
ODSSupport.h
Go to the documentation of this file.
1//===- ODSSupport.h ---------------------------------------------*- 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 file defines a number of support method for ODS generated code.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef MLIR_IR_ODSSUPPORT_H
14#define MLIR_IR_ODSSUPPORT_H
15
16#include "mlir/IR/Attributes.h"
17#include "mlir/IR/MLIRContext.h"
18#include "mlir/Support/LLVM.h"
19
20namespace mlir {
21
22//===----------------------------------------------------------------------===//
23// Support for properties
24//===----------------------------------------------------------------------===//
25
26/// Convert an IntegerAttr attribute to an int64_t, or return an error if the
27/// attribute isn't an IntegerAttr. If the optional diagnostic is provided an
28/// error message is also emitted.
29LogicalResult
30convertFromAttribute(int64_t &storage, Attribute attr,
32
33/// Convert the provided int64_t to an IntegerAttr attribute.
34Attribute convertToAttribute(MLIRContext *ctx, int64_t storage);
35
36/// Convert an IntegerAttr attribute to an int32_t, or return an error if the
37/// attribute isn't an IntegerAttr. If the optional diagnostic is provided an
38/// error message is also emitted.
39LogicalResult
40convertFromAttribute(int32_t &storage, Attribute attr,
42
43/// Convert the provided int32_t to an IntegerAttr attribute.
44Attribute convertToAttribute(MLIRContext *ctx, int32_t storage);
45
46/// Convert an IntegerAttr attribute to an int8_t, or return an error if the
47/// attribute isn't an IntegerAttr. If the optional diagnostic is provided an
48/// error message is also emitted.
49LogicalResult
50convertFromAttribute(int8_t &storage, Attribute attr,
52
53/// Convert the provided int8_t to an IntegerAttr attribute.
54Attribute convertToAttribute(MLIRContext *ctx, int8_t storage);
55
56/// Convert an IntegerAttr attribute to an uint8_t, or return an error if the
57/// attribute isn't an IntegerAttr. If the optional diagnostic is provided an
58/// error message is also emitted.
59LogicalResult
60convertFromAttribute(uint8_t &storage, Attribute attr,
62
63/// Convert the provided uint8_t to an IntegerAttr attribute.
64Attribute convertToAttribute(MLIRContext *ctx, uint8_t storage);
65
66/// Extract the string from `attr` into `storage`. If `attr` is not a
67/// `StringAttr`, return failure and emit an error into the diagnostic from
68/// `emitError`.
69LogicalResult
70convertFromAttribute(std::string &storage, Attribute attr,
72
73/// Convert the given string into a StringAttr. Note that this takes a reference
74/// to the storage of a string property, which is an std::string.
75Attribute convertToAttribute(MLIRContext *ctx, const std::string &storage);
76
77/// Extract the boolean from `attr` into `storage`. If `attr` is not a
78/// `BoolAttr`, return failure and emit an error into the diagnostic from
79/// `emitError`.
80LogicalResult
81convertFromAttribute(bool &storage, Attribute attr,
83
84/// Convert the given string into a BooleanAttr.
85Attribute convertToAttribute(MLIRContext *ctx, bool storage);
86
87/// Convert a DenseI64ArrayAttr to the provided storage. It is expected that the
88/// storage has the same size as the array. An error is returned if the
89/// attribute isn't a DenseI64ArrayAttr or it does not have the same size. If
90/// the optional diagnostic is provided an error message is also emitted.
91LogicalResult
94
95/// Convert a DenseI32ArrayAttr to the provided storage. It is expected that the
96/// storage has the same size as the array. An error is returned if the
97/// attribute isn't a DenseI32ArrayAttr or it does not have the same size. If
98/// the optional diagnostic is provided an error message is also emitted.
99LogicalResult
102
103/// Convert a DenseI64ArrayAttr to the provided storage, which will be
104/// cleared before writing. An error is returned and emitted to the optional
105/// `emitError` function if the attribute isn't a DenseI64ArrayAttr.
106LogicalResult
109
110/// Convert a DenseI32ArrayAttr to the provided storage, which will be
111/// cleared before writing. It is expected that the storage has the same size as
112/// the array. An error is returned and emitted to the optional `emitError`
113/// function if the attribute isn't a DenseI32ArrayAttr.
114LogicalResult
117
118/// Convert the provided ArrayRef<int64_t> to a DenseI64ArrayAttr attribute.
120
121/// Convert the provided ArrayRef<int32_t> to a DenseI32ArrayAttr attribute.
123
124} // namespace mlir
125
126#endif // MLIR_IR_ODSSUPPORT_H
Attributes are known-constant values of operations.
Definition Attributes.h:25
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:63
Include the generated interface declarations.
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
Attribute convertToAttribute(MLIRContext *ctx, int64_t storage)
Convert the provided int64_t to an IntegerAttr attribute.
LogicalResult convertFromAttribute(int64_t &storage, Attribute attr, function_ref< InFlightDiagnostic()> emitError)
Convert an IntegerAttr attribute to an int64_t, or return an error if the attribute isn't an IntegerA...
llvm::function_ref< Fn > function_ref
Definition LLVM.h:152