MLIR: lib/IR/ODSSupport.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
18
19 using namespace mlir;
20
21 LogicalResult
24 auto valueAttr = dyn_cast(attr);
25 if (!valueAttr) {
26 emitError() << "expected IntegerAttr for key `value`";
27 return failure();
28 }
29 storage = valueAttr.getValue().getSExtValue();
30 return success();
31 }
34 }
35
36 LogicalResult
39 auto valueAttr = dyn_cast(attr);
40 if (!valueAttr) {
41 emitError() << "expected IntegerAttr for key `value`";
42 return failure();
43 }
44 storage = valueAttr.getValue().getSExtValue();
45 return success();
46 }
49 }
50
51 LogicalResult
54 auto valueAttr = dyn_cast(attr);
55 if (!valueAttr)
57 << "expected string property to come from string attribute";
58 storage = valueAttr.getValue().str();
59 return success();
60 }
62 const std::string &storage) {
64 }
65
66 LogicalResult
69 auto valueAttr = dyn_cast(attr);
70 if (!valueAttr)
72 << "expected string property to come from string attribute";
73 storage = valueAttr.getValue();
74 return success();
75 }
78 }
79
80 template <typename DenseArrayTy, typename T>
81 LogicalResult
84 StringRef denseArrayTyStr) {
85 auto valueAttr = dyn_cast(attr);
86 if (!valueAttr) {
87 emitError() << "expected " << denseArrayTyStr << " for key `value`";
88 return failure();
89 }
90 if (valueAttr.size() != static_cast<int64_t>(storage.size())) {
91 emitError() << "size mismatch in attribute conversion: " << valueAttr.size()
92 << " vs " << storage.size();
93 return failure();
94 }
95 llvm::copy(valueAttr.asArrayRef(), storage.begin());
96 return success();
97 }
98 LogicalResult
101 return convertDenseArrayFromAttr(storage, attr, emitError,
102 "DenseI64ArrayAttr");
103 }
104 LogicalResult
107 return convertDenseArrayFromAttr(storage, attr, emitError,
108 "DenseI32ArrayAttr");
109 }
110
111 template <typename DenseArrayTy, typename T>
112 LogicalResult
115 StringRef denseArrayTyStr) {
116 auto valueAttr = dyn_cast(attr);
117 if (!valueAttr) {
118 emitError() << "expected " << denseArrayTyStr << " for key `value`";
119 return failure();
120 }
121 storage.resize_for_overwrite(valueAttr.size());
122 llvm::copy(valueAttr.asArrayRef(), storage.begin());
123 return success();
124 }
125 LogicalResult
128 return convertDenseArrayFromAttr(storage, attr, emitError,
129 "DenseI64ArrayAttr");
130 }
131 LogicalResult
134 return convertDenseArrayFromAttr(storage, attr, emitError,
135 "DenseI32ArrayAttr");
136 }
137
141 }
static void copy(Location loc, Value dst, Value src, Value size, OpBuilder &builder)
Copies the given number of bytes from src to dst pointers.
LogicalResult convertDenseArrayFromAttr(MutableArrayRef< T > storage, Attribute attr, function_ref< InFlightDiagnostic()> emitError, StringRef denseArrayTyStr)
Attributes are known-constant values of operations.
static BoolAttr get(MLIRContext *context, bool value)
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.
static DenseArrayAttrImpl get(MLIRContext *context, ArrayRef< T > content)
Builder from ArrayRef.
Include the generated interface declarations.
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
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...