24 auto valueAttr = dyn_cast<IntegerAttr>(attr);
26 emitError() <<
"expected IntegerAttr for key `value`";
29 storage = valueAttr.getValue().getSExtValue();
39 auto valueAttr = dyn_cast<IntegerAttr>(attr);
41 emitError() <<
"expected IntegerAttr for key `value`";
44 storage = valueAttr.getValue().getSExtValue();
54 auto valueAttr = dyn_cast<StringAttr>(attr);
57 <<
"expected string property to come from string attribute";
58 storage = valueAttr.getValue().str();
62 const std::string &storage) {
69 auto valueAttr = dyn_cast<BoolAttr>(attr);
72 <<
"expected string property to come from string attribute";
73 storage = valueAttr.getValue();
80 template <
typename DenseArrayTy,
typename T>
84 StringRef denseArrayTyStr) {
85 auto valueAttr = dyn_cast<DenseArrayTy>(attr);
87 emitError() <<
"expected " << denseArrayTyStr <<
" for key `value`";
90 if (valueAttr.size() !=
static_cast<int64_t
>(storage.size())) {
91 emitError() <<
"size mismatch in attribute conversion: " << valueAttr.size()
92 <<
" vs " << storage.size();
95 llvm::copy(valueAttr.asArrayRef(), storage.begin());
101 return convertDenseArrayFromAttr<DenseI64ArrayAttr>(storage, attr,
emitError,
102 "DenseI64ArrayAttr");
107 return convertDenseArrayFromAttr<DenseI32ArrayAttr>(storage, attr,
emitError,
108 "DenseI32ArrayAttr");
111 template <
typename DenseArrayTy,
typename T>
115 StringRef denseArrayTyStr) {
116 auto valueAttr = dyn_cast<DenseArrayTy>(attr);
118 emitError() <<
"expected " << denseArrayTyStr <<
" for key `value`";
121 storage.resize_for_overwrite(valueAttr.size());
122 llvm::copy(valueAttr.asArrayRef(), storage.begin());
128 return convertDenseArrayFromAttr<DenseI64ArrayAttr>(storage, attr,
emitError,
129 "DenseI64ArrayAttr");
134 return convertDenseArrayFromAttr<DenseI32ArrayAttr>(storage, attr,
emitError,
135 "DenseI32ArrayAttr");
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<T>.
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...