-
Notifications
You must be signed in to change notification settings - Fork 437
Expand file tree
/
Copy pathHW.h
More file actions
272 lines (202 loc) · 11.2 KB
/
HW.h
File metadata and controls
272 lines (202 loc) · 11.2 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
//===- HW.h - C interface for the HW dialect ----------------------*- C -*-===//
//
// Part of the LLVM 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
//
//===----------------------------------------------------------------------===//
#ifndef CIRCT_C_DIALECT_HW_H
#define CIRCT_C_DIALECT_HW_H
#include "mlir-c/IR.h"
#ifdef __cplusplus
extern "C" {
#endif
#define DEFINE_C_API_STRUCT(name, storage) \
struct name { \
storage *ptr; \
}; \
typedef struct name name
DEFINE_C_API_STRUCT(HWInstanceGraph, void);
DEFINE_C_API_STRUCT(HWInstanceGraphNode, void);
#undef DEFINE_C_API_STRUCT
struct HWStructFieldInfo {
MlirIdentifier name;
MlirType type;
};
typedef struct HWStructFieldInfo HWStructFieldInfo;
struct HWUnionFieldInfo {
MlirIdentifier name;
MlirType type;
size_t offset;
};
typedef struct HWUnionFieldInfo HWUnionFieldInfo;
enum HWModulePortDirection { Input, Output, InOut };
typedef enum HWModulePortDirection HWModulePortDirection;
struct HWModulePort {
MlirAttribute name;
MlirType type;
HWModulePortDirection dir;
};
typedef struct HWModulePort HWModulePort;
//===----------------------------------------------------------------------===//
// Dialect API.
//===----------------------------------------------------------------------===//
MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(HW, hw);
MLIR_CAPI_EXPORTED void registerHWPasses(void);
//===----------------------------------------------------------------------===//
// Type API.
//===----------------------------------------------------------------------===//
/// Return the hardware bit width of a type. Does not reflect any encoding,
/// padding, or storage scheme, just the bit (and wire width) of a
/// statically-size type. Reflects the number of wires needed to transmit a
/// value of this type. Returns -1 if the type is not known or cannot be
/// statically computed.
MLIR_CAPI_EXPORTED int64_t hwGetBitWidth(MlirType);
/// Return true if the specified type can be used as an HW value type, that is
/// the set of types that can be composed together to represent synthesized,
/// hardware but not marker types like InOutType or unknown types from other
/// dialects.
MLIR_CAPI_EXPORTED bool hwTypeIsAValueType(MlirType);
MLIR_CAPI_EXPORTED bool hwTypeIsAIntType(MlirType);
MLIR_CAPI_EXPORTED MlirTypeID hwIntTypeGetTypeID(void);
/// If the type is an HW array
MLIR_CAPI_EXPORTED bool hwTypeIsAArrayType(MlirType);
MLIR_CAPI_EXPORTED MlirTypeID hwArrayTypeGetTypeID(void);
/// If the type is an HW inout.
MLIR_CAPI_EXPORTED bool hwTypeIsAInOut(MlirType type);
MLIR_CAPI_EXPORTED MlirTypeID hwInOutTypeGetTypeID(void);
/// If the type is an HW module type.
MLIR_CAPI_EXPORTED bool hwTypeIsAModuleType(MlirType type);
MLIR_CAPI_EXPORTED MlirTypeID hwModuleTypeGetTypeID(void);
/// If the type is an HW struct.
MLIR_CAPI_EXPORTED bool hwTypeIsAStructType(MlirType);
MLIR_CAPI_EXPORTED MlirTypeID hwStructTypeGetTypeID(void);
/// If the type is an HW union.
MLIR_CAPI_EXPORTED bool hwTypeIsAUnionType(MlirType);
MLIR_CAPI_EXPORTED MlirTypeID hwUnionTypeGetTypeID(void);
/// If the type is an HW type alias.
MLIR_CAPI_EXPORTED bool hwTypeIsATypeAliasType(MlirType);
MLIR_CAPI_EXPORTED MlirTypeID hwTypeAliasTypeGetTypeID(void);
/// Creates a fixed-size HW array type in the context associated with element
MLIR_CAPI_EXPORTED MlirType hwArrayTypeGet(MlirType element, size_t size);
/// returns the element type of an array type
MLIR_CAPI_EXPORTED MlirType hwArrayTypeGetElementType(MlirType);
/// returns the size of an array type
MLIR_CAPI_EXPORTED intptr_t hwArrayTypeGetSize(MlirType);
/// Creates an HW inout type in the context associated with element.
MLIR_CAPI_EXPORTED MlirType hwInOutTypeGet(MlirType element);
/// Returns the element type of an inout type.
MLIR_CAPI_EXPORTED MlirType hwInOutTypeGetElementType(MlirType);
/// Creates an HW module type.
MLIR_CAPI_EXPORTED MlirType hwModuleTypeGet(MlirContext ctx, intptr_t numPorts,
HWModulePort const *ports);
/// Get an HW module type's number of inputs.
MLIR_CAPI_EXPORTED intptr_t hwModuleTypeGetNumInputs(MlirType type);
/// Get an HW module type's input type at a specific index.
MLIR_CAPI_EXPORTED MlirType hwModuleTypeGetInputType(MlirType type,
intptr_t index);
/// Get an HW module type's input name at a specific index.
MLIR_CAPI_EXPORTED MlirStringRef hwModuleTypeGetInputName(MlirType type,
intptr_t index);
/// Get an HW module type's number of outputs.
MLIR_CAPI_EXPORTED intptr_t hwModuleTypeGetNumOutputs(MlirType type);
/// Get an HW module type's output type at a specific index.
MLIR_CAPI_EXPORTED MlirType hwModuleTypeGetOutputType(MlirType type,
intptr_t index);
/// Get an HW module type's output name at a specific index.
MLIR_CAPI_EXPORTED MlirStringRef hwModuleTypeGetOutputName(MlirType type,
intptr_t index);
/// Get an HW module type's port info at a specific index.
MLIR_CAPI_EXPORTED void hwModuleTypeGetPort(MlirType type, intptr_t index,
HWModulePort *ret);
/// Creates an HW struct type in the context associated with the elements.
MLIR_CAPI_EXPORTED MlirType hwStructTypeGet(MlirContext ctx,
intptr_t numElements,
HWStructFieldInfo const *elements);
MLIR_CAPI_EXPORTED MlirType hwStructTypeGetField(MlirType structType,
MlirStringRef fieldName);
MLIR_CAPI_EXPORTED MlirType hwParamIntTypeGet(MlirAttribute parameter);
MLIR_CAPI_EXPORTED MlirAttribute hwParamIntTypeGetWidthAttr(MlirType);
MLIR_CAPI_EXPORTED MlirAttribute
hwStructTypeGetFieldIndex(MlirType structType, MlirStringRef fieldName);
MLIR_CAPI_EXPORTED HWStructFieldInfo
hwStructTypeGetFieldNum(MlirType structType, unsigned idx);
MLIR_CAPI_EXPORTED intptr_t hwStructTypeGetNumFields(MlirType structType);
/// Creates an HW union type in the context associated with the elements.
MLIR_CAPI_EXPORTED MlirType hwUnionTypeGet(MlirContext ctx,
intptr_t numElements,
HWUnionFieldInfo const *elements);
MLIR_CAPI_EXPORTED MlirType hwUnionTypeGetField(MlirType unionType,
MlirStringRef fieldName);
MLIR_CAPI_EXPORTED MlirAttribute
hwUnionTypeGetFieldIndex(MlirType unionType, MlirStringRef fieldName);
MLIR_CAPI_EXPORTED HWUnionFieldInfo hwUnionTypeGetFieldNum(MlirType unionType,
unsigned idx);
MLIR_CAPI_EXPORTED intptr_t hwUnionTypeGetNumFields(MlirType unionType);
MLIR_CAPI_EXPORTED MlirType hwTypeAliasTypeGet(MlirStringRef scope,
MlirStringRef name,
MlirType innerType);
MLIR_CAPI_EXPORTED MlirType hwTypeAliasTypeGetCanonicalType(MlirType typeAlias);
MLIR_CAPI_EXPORTED MlirType hwTypeAliasTypeGetInnerType(MlirType typeAlias);
MLIR_CAPI_EXPORTED MlirStringRef hwTypeAliasTypeGetName(MlirType typeAlias);
MLIR_CAPI_EXPORTED MlirStringRef hwTypeAliasTypeGetScope(MlirType typeAlias);
//===----------------------------------------------------------------------===//
// Attribute API.
//===----------------------------------------------------------------------===//
MLIR_CAPI_EXPORTED bool hwAttrIsAInnerSymAttr(MlirAttribute);
MLIR_CAPI_EXPORTED MlirTypeID hwInnerSymAttrGetTypeID(void);
MLIR_CAPI_EXPORTED MlirAttribute hwInnerSymAttrGet(MlirAttribute symName);
MLIR_CAPI_EXPORTED MlirAttribute hwInnerSymAttrGetEmpty(MlirContext ctx);
MLIR_CAPI_EXPORTED MlirAttribute hwInnerSymAttrGetSymName(MlirAttribute);
MLIR_CAPI_EXPORTED bool hwAttrIsAInnerRefAttr(MlirAttribute);
MLIR_CAPI_EXPORTED MlirTypeID hwInnerRefAttrGetTypeID(void);
MLIR_CAPI_EXPORTED MlirAttribute hwInnerRefAttrGet(MlirAttribute moduleName,
MlirAttribute innerSym);
MLIR_CAPI_EXPORTED MlirAttribute hwInnerRefAttrGetName(MlirAttribute);
MLIR_CAPI_EXPORTED MlirAttribute hwInnerRefAttrGetModule(MlirAttribute);
MLIR_CAPI_EXPORTED bool hwAttrIsAParamDeclAttr(MlirAttribute);
MLIR_CAPI_EXPORTED MlirTypeID hwParamDeclAttrGetTypeID(void);
MLIR_CAPI_EXPORTED MlirAttribute hwParamDeclAttrGet(MlirStringRef name,
MlirType type,
MlirAttribute value);
MLIR_CAPI_EXPORTED MlirStringRef hwParamDeclAttrGetName(MlirAttribute decl);
MLIR_CAPI_EXPORTED MlirType hwParamDeclAttrGetType(MlirAttribute decl);
MLIR_CAPI_EXPORTED MlirAttribute hwParamDeclAttrGetValue(MlirAttribute decl);
MLIR_CAPI_EXPORTED bool hwAttrIsAParamDeclRefAttr(MlirAttribute);
MLIR_CAPI_EXPORTED MlirTypeID hwParamDeclRefAttrGetTypeID(void);
MLIR_CAPI_EXPORTED MlirAttribute hwParamDeclRefAttrGet(MlirContext ctx,
MlirStringRef cName);
MLIR_CAPI_EXPORTED MlirStringRef hwParamDeclRefAttrGetName(MlirAttribute decl);
MLIR_CAPI_EXPORTED MlirType hwParamDeclRefAttrGetType(MlirAttribute decl);
MLIR_CAPI_EXPORTED bool hwAttrIsAParamVerbatimAttr(MlirAttribute);
MLIR_CAPI_EXPORTED MlirTypeID hwParamVerbatimAttrGetTypeID(void);
MLIR_CAPI_EXPORTED MlirAttribute hwParamVerbatimAttrGet(MlirAttribute text);
MLIR_CAPI_EXPORTED bool hwAttrIsAOutputFileAttr(MlirAttribute);
MLIR_CAPI_EXPORTED MlirTypeID hwOutputFileAttrGetTypeID(void);
MLIR_CAPI_EXPORTED MlirAttribute hwOutputFileGetFromFileName(
MlirAttribute text, bool excludeFromFileList, bool includeReplicatedOp);
MLIR_CAPI_EXPORTED MlirStringRef
hwOutputFileGetFileName(MlirAttribute outputFile);
//===----------------------------------------------------------------------===//
// InstanceGraph API.
//===----------------------------------------------------------------------===//
MLIR_CAPI_EXPORTED HWInstanceGraph hwInstanceGraphGet(MlirOperation operation);
MLIR_CAPI_EXPORTED void hwInstanceGraphDestroy(HWInstanceGraph instanceGraph);
MLIR_CAPI_EXPORTED HWInstanceGraphNode
hwInstanceGraphGetTopLevelNode(HWInstanceGraph instanceGraph);
// NOLINTNEXTLINE(modernize-use-using)
typedef void (*HWInstanceGraphNodeCallback)(HWInstanceGraphNode, void *);
MLIR_CAPI_EXPORTED void
hwInstanceGraphForEachNode(HWInstanceGraph instanceGraph,
HWInstanceGraphNodeCallback callback,
void *userData);
MLIR_CAPI_EXPORTED bool hwInstanceGraphNodeEqual(HWInstanceGraphNode lhs,
HWInstanceGraphNode rhs);
MLIR_CAPI_EXPORTED MlirModule
hwInstanceGraphNodeGetModule(HWInstanceGraphNode node);
MLIR_CAPI_EXPORTED MlirOperation
hwInstanceGraphNodeGetModuleOp(HWInstanceGraphNode node);
#ifdef __cplusplus
}
#endif
#endif // CIRCT_C_DIALECT_HW_H