Core.h
4.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*===-- mlir-c/Core.h - Core Library C Interface ------------------*- C -*-===*\
|* *|
|* Part of the MLIR Project, under the Apache License v2.0 with LLVM *|
|* Exceptions. *|
|* See https://llvm.org/LICENSE.txt for license information. *|
|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
|* *|
|*===----------------------------------------------------------------------===*|
|* *|
|* This header declares the C interface to MLIR. *|
|* *|
\*===----------------------------------------------------------------------===*/
#ifndef MLIR_C_CORE_H
#define MLIR_C_CORE_H
#ifdef __cplusplus
#include <cstdint>
extern "C" {
#else
#include <stdint.h>
#endif
/// Opaque MLIR types.
/// Opaque C type for mlir::MLIRContext*.
typedef void *mlir_context_t;
/// Opaque C type for mlir::Type.
typedef const void *mlir_type_t;
/// Opaque C type for mlir::FuncOp.
typedef void *mlir_func_t;
/// Opaque C type for mlir::Attribute.
typedef const void *mlir_attr_t;
/// Simple C lists for non-owning mlir Opaque C types.
/// Recommended usage is construction from the `data()` and `size()` of a scoped
/// owning SmallVectorImpl<...> and passing to one of the C functions declared
/// later in this file.
/// Once the function returns and the proper EDSC has been constructed,
/// resources are freed by exiting the scope.
typedef struct {
int64_t *values;
uint64_t n;
} int64_list_t;
typedef struct {
mlir_type_t *types;
uint64_t n;
} mlir_type_list_t;
typedef struct {
const char *name;
mlir_attr_t value;
} mlir_named_attr_t;
typedef struct {
mlir_named_attr_t *list;
uint64_t n;
} mlir_named_attr_list_t;
/// Minimal C API for exposing EDSCs to Swift, Python and other languages.
/// Returns an `mlir::MemRefType` of the element type `elemType` and shape
/// `sizes`.
mlir_type_t makeMemRefType(mlir_context_t context, mlir_type_t elemType,
int64_list_t sizes);
/// Returns an `mlir::FunctionType` of the element type `elemType` and shape
/// `sizes`.
mlir_type_t makeFunctionType(mlir_context_t context, mlir_type_list_t inputs,
mlir_type_list_t outputs);
/// Returns an `mlir::IndexType`.
mlir_type_t makeIndexType(mlir_context_t context);
/// Returns an `mlir::IntegerAttr` of the specified type that contains the given
/// value.
mlir_attr_t makeIntegerAttr(mlir_type_t type, int64_t value);
/// Returns an `mlir::BoolAttr` with the given value.
mlir_attr_t makeBoolAttr(mlir_context_t context, bool value);
/// Returns an `mlir::FloatAttr` with the given value.
mlir_attr_t makeFloatAttr(mlir_context_t context, float value);
/// Returns an `mlir::StringAttr` with the given value.
mlir_attr_t makeStringAttr(mlir_context_t context, const char *value);
/// Parses an MLIR type from the string `type` in the given context. Returns a
/// NULL type on error. If non-NULL, `charsRead` will contain the number of
/// characters that were processed by the parser.
mlir_type_t mlirParseType(const char *type, mlir_context_t context,
uint64_t *charsRead);
/// Returns the arity of `function`.
unsigned getFunctionArity(mlir_func_t function);
/// Returns the rank of the `function` argument at position `pos`.
/// If the argument is of MemRefType, this returns the rank of the MemRef.
/// Otherwise returns `0`.
/// TODO(ntv): support more than MemRefType and scalar Type.
unsigned getRankOfFunctionArgument(mlir_func_t function, unsigned pos);
/// Returns an opaque mlir::Type of the `function` argument at position `pos`.
mlir_type_t getTypeOfFunctionArgument(mlir_func_t function, unsigned pos);
#ifdef __cplusplus
} // end extern "C"
#endif
#endif // MLIR_C_CORE_H