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,
31 function_ref<InFlightDiagnostic()> emitError);
32
33/// Convert the provided int64_t to an IntegerAttr attribute.
34Attribute convertToAttribute(MLIRContext *ctx, int64_t storage);
35
36/// Convert a DenseI64ArrayAttr to the provided storage. It is expected that the
37/// storage has the same size as the array. An error is returned if the
38/// attribute isn't a DenseI64ArrayAttr or it does not have the same size. If
39/// the optional diagnostic is provided an error message is also emitted.
40LogicalResult
41convertFromAttribute(MutableArrayRef<int64_t> storage, Attribute attr,
42 function_ref<InFlightDiagnostic()> emitError);
43
44/// Convert a DenseI32ArrayAttr to the provided storage. It is expected that the
45/// storage has the same size as the array. An error is returned if the
46/// attribute isn't a DenseI32ArrayAttr or it does not have the same size. If
47/// the optional diagnostic is provided an error message is also emitted.
48LogicalResult
49convertFromAttribute(MutableArrayRef<int32_t> storage, Attribute attr,
50 function_ref<InFlightDiagnostic()> emitError);
51
52/// Convert the provided ArrayRef<int64_t> to a DenseI64ArrayAttr attribute.
53Attribute convertToAttribute(MLIRContext *ctx, ArrayRef<int64_t> storage);
54
55} // namespace mlir
56
57#endif // MLIR_IR_ODSSUPPORT_H

source code of mlir/include/mlir/IR/ODSSupport.h