MLIR  19.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 
20 namespace 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.
29 LogicalResult
30 convertFromAttribute(int64_t &storage, Attribute attr,
31  function_ref<InFlightDiagnostic()> emitError);
32 
33 /// Convert the provided int64_t to an IntegerAttr attribute.
34 Attribute 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.
40 LogicalResult
41 convertFromAttribute(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.
48 LogicalResult
49 convertFromAttribute(MutableArrayRef<int32_t> storage, Attribute attr,
50  function_ref<InFlightDiagnostic()> emitError);
51 
52 /// Convert the provided ArrayRef<int64_t> to a DenseI64ArrayAttr attribute.
53 Attribute convertToAttribute(MLIRContext *ctx, ArrayRef<int64_t> storage);
54 
55 } // namespace mlir
56 
57 #endif // MLIR_IR_ODSSUPPORT_H
Include the generated interface declarations.
llvm::function_ref< Fn > function_ref
Definition: LLVM.h:147
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.
Definition: ODSSupport.cpp:32
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...
Definition: ODSSupport.cpp:22