CIRCT 22.0.0git
Loading...
Searching...
No Matches
HW.h
Go to the documentation of this file.
1//===- HW.h - C interface for the HW dialect ----------------------*- 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#ifndef CIRCT_C_DIALECT_HW_H
10#define CIRCT_C_DIALECT_HW_H
11
12#include "mlir-c/IR.h"
13
14#ifdef __cplusplus
15extern "C" {
16#endif
17
18#define DEFINE_C_API_STRUCT(name, storage) \
19 struct name { \
20 storage *ptr; \
21 }; \
22 typedef struct name name
23
24DEFINE_C_API_STRUCT(HWInstanceGraph, void);
25DEFINE_C_API_STRUCT(HWInstanceGraphNode, void);
26
27#undef DEFINE_C_API_STRUCT
28
30 MlirIdentifier name;
31 MlirType type;
32};
34
36 MlirIdentifier name;
37 MlirType type;
38 size_t offset;
39};
41
44
46 MlirAttribute name;
47 MlirType type;
49};
51
52//===----------------------------------------------------------------------===//
53// Dialect API.
54//===----------------------------------------------------------------------===//
55
57MLIR_CAPI_EXPORTED void registerHWPasses(void);
58
59//===----------------------------------------------------------------------===//
60// Type API.
61//===----------------------------------------------------------------------===//
62
63/// Return the hardware bit width of a type. Does not reflect any encoding,
64/// padding, or storage scheme, just the bit (and wire width) of a
65/// statically-size type. Reflects the number of wires needed to transmit a
66/// value of this type. Returns -1 if the type is not known or cannot be
67/// statically computed.
68MLIR_CAPI_EXPORTED int64_t hwGetBitWidth(MlirType);
69
70/// Return true if the specified type can be used as an HW value type, that is
71/// the set of types that can be composed together to represent synthesized,
72/// hardware but not marker types like InOutType or unknown types from other
73/// dialects.
74MLIR_CAPI_EXPORTED bool hwTypeIsAValueType(MlirType);
75
76/// If the type is an HW array
77MLIR_CAPI_EXPORTED bool hwTypeIsAArrayType(MlirType);
78
79/// If the type is an HW inout.
80MLIR_CAPI_EXPORTED bool hwTypeIsAInOut(MlirType type);
81
82/// If the type is an HW module type.
83MLIR_CAPI_EXPORTED bool hwTypeIsAModuleType(MlirType type);
84
85/// If the type is an HW struct.
86MLIR_CAPI_EXPORTED bool hwTypeIsAStructType(MlirType);
87
88/// If the type is an HW union.
89MLIR_CAPI_EXPORTED bool hwTypeIsAUnionType(MlirType);
90
91/// If the type is an HW type alias.
92MLIR_CAPI_EXPORTED bool hwTypeIsATypeAliasType(MlirType);
93
94/// If the type is an HW int.
95MLIR_CAPI_EXPORTED bool hwTypeIsAIntType(MlirType);
96
97/// Creates a fixed-size HW array type in the context associated with element
98MLIR_CAPI_EXPORTED MlirType hwArrayTypeGet(MlirType element, size_t size);
99
100/// returns the element type of an array type
101MLIR_CAPI_EXPORTED MlirType hwArrayTypeGetElementType(MlirType);
102
103/// returns the size of an array type
104MLIR_CAPI_EXPORTED intptr_t hwArrayTypeGetSize(MlirType);
105
106/// Creates an HW inout type in the context associated with element.
107MLIR_CAPI_EXPORTED MlirType hwInOutTypeGet(MlirType element);
108
109/// Returns the element type of an inout type.
110MLIR_CAPI_EXPORTED MlirType hwInOutTypeGetElementType(MlirType);
111
112/// Creates an HW module type.
113MLIR_CAPI_EXPORTED MlirType hwModuleTypeGet(MlirContext ctx, intptr_t numPorts,
114 HWModulePort const *ports);
115
116/// Get an HW module type's number of inputs.
117MLIR_CAPI_EXPORTED intptr_t hwModuleTypeGetNumInputs(MlirType type);
118
119/// Get an HW module type's input type at a specific index.
120MLIR_CAPI_EXPORTED MlirType hwModuleTypeGetInputType(MlirType type,
121 intptr_t index);
122
123/// Get an HW module type's input name at a specific index.
124MLIR_CAPI_EXPORTED MlirStringRef hwModuleTypeGetInputName(MlirType type,
125 intptr_t index);
126
127/// Get an HW module type's number of outputs.
128MLIR_CAPI_EXPORTED intptr_t hwModuleTypeGetNumOutputs(MlirType type);
129
130/// Get an HW module type's output type at a specific index.
131MLIR_CAPI_EXPORTED MlirType hwModuleTypeGetOutputType(MlirType type,
132 intptr_t index);
133
134/// Get an HW module type's output name at a specific index.
135MLIR_CAPI_EXPORTED MlirStringRef hwModuleTypeGetOutputName(MlirType type,
136 intptr_t index);
137
138/// Get an HW module type's port info at a specific index.
139MLIR_CAPI_EXPORTED void hwModuleTypeGetPort(MlirType type, intptr_t index,
140 HWModulePort *ret);
141
142/// Creates an HW struct type in the context associated with the elements.
143MLIR_CAPI_EXPORTED MlirType hwStructTypeGet(MlirContext ctx,
144 intptr_t numElements,
145 HWStructFieldInfo const *elements);
146
147MLIR_CAPI_EXPORTED MlirType hwStructTypeGetField(MlirType structType,
148 MlirStringRef fieldName);
149
150MLIR_CAPI_EXPORTED MlirType hwParamIntTypeGet(MlirAttribute parameter);
151
152MLIR_CAPI_EXPORTED MlirAttribute hwParamIntTypeGetWidthAttr(MlirType);
153
154MLIR_CAPI_EXPORTED MlirAttribute
155hwStructTypeGetFieldIndex(MlirType structType, MlirStringRef fieldName);
156
157MLIR_CAPI_EXPORTED HWStructFieldInfo
158hwStructTypeGetFieldNum(MlirType structType, unsigned idx);
159
160MLIR_CAPI_EXPORTED intptr_t hwStructTypeGetNumFields(MlirType structType);
161
162/// Creates an HW union type in the context associated with the elements.
163MLIR_CAPI_EXPORTED MlirType hwUnionTypeGet(MlirContext ctx,
164 intptr_t numElements,
165 HWUnionFieldInfo const *elements);
166
167MLIR_CAPI_EXPORTED MlirType hwUnionTypeGetField(MlirType unionType,
168 MlirStringRef fieldName);
169
170MLIR_CAPI_EXPORTED MlirAttribute
171hwUnionTypeGetFieldIndex(MlirType unionType, MlirStringRef fieldName);
172
173MLIR_CAPI_EXPORTED HWUnionFieldInfo hwUnionTypeGetFieldNum(MlirType unionType,
174 unsigned idx);
175
176MLIR_CAPI_EXPORTED intptr_t hwUnionTypeGetNumFields(MlirType unionType);
177
178MLIR_CAPI_EXPORTED MlirType hwTypeAliasTypeGet(MlirStringRef scope,
179 MlirStringRef name,
180 MlirType innerType);
181
182MLIR_CAPI_EXPORTED MlirType hwTypeAliasTypeGetCanonicalType(MlirType typeAlias);
183
184MLIR_CAPI_EXPORTED MlirType hwTypeAliasTypeGetInnerType(MlirType typeAlias);
185
186MLIR_CAPI_EXPORTED MlirStringRef hwTypeAliasTypeGetName(MlirType typeAlias);
187
188MLIR_CAPI_EXPORTED MlirStringRef hwTypeAliasTypeGetScope(MlirType typeAlias);
189
190//===----------------------------------------------------------------------===//
191// Attribute API.
192//===----------------------------------------------------------------------===//
193
194MLIR_CAPI_EXPORTED bool hwAttrIsAInnerSymAttr(MlirAttribute);
195MLIR_CAPI_EXPORTED MlirAttribute hwInnerSymAttrGet(MlirAttribute symName);
196MLIR_CAPI_EXPORTED MlirAttribute hwInnerSymAttrGetEmpty(MlirContext ctx);
197MLIR_CAPI_EXPORTED MlirAttribute hwInnerSymAttrGetSymName(MlirAttribute);
198
199MLIR_CAPI_EXPORTED bool hwAttrIsAInnerRefAttr(MlirAttribute);
200MLIR_CAPI_EXPORTED MlirAttribute hwInnerRefAttrGet(MlirAttribute moduleName,
201 MlirAttribute innerSym);
202MLIR_CAPI_EXPORTED MlirAttribute hwInnerRefAttrGetName(MlirAttribute);
203MLIR_CAPI_EXPORTED MlirAttribute hwInnerRefAttrGetModule(MlirAttribute);
204
205MLIR_CAPI_EXPORTED bool hwAttrIsAParamDeclAttr(MlirAttribute);
206MLIR_CAPI_EXPORTED MlirAttribute hwParamDeclAttrGet(MlirStringRef name,
207 MlirType type,
208 MlirAttribute value);
209MLIR_CAPI_EXPORTED MlirStringRef hwParamDeclAttrGetName(MlirAttribute decl);
210MLIR_CAPI_EXPORTED MlirType hwParamDeclAttrGetType(MlirAttribute decl);
211MLIR_CAPI_EXPORTED MlirAttribute hwParamDeclAttrGetValue(MlirAttribute decl);
212
213MLIR_CAPI_EXPORTED bool hwAttrIsAParamDeclRefAttr(MlirAttribute);
214MLIR_CAPI_EXPORTED MlirAttribute hwParamDeclRefAttrGet(MlirContext ctx,
215 MlirStringRef cName);
216MLIR_CAPI_EXPORTED MlirStringRef hwParamDeclRefAttrGetName(MlirAttribute decl);
217MLIR_CAPI_EXPORTED MlirType hwParamDeclRefAttrGetType(MlirAttribute decl);
218
219MLIR_CAPI_EXPORTED bool hwAttrIsAParamVerbatimAttr(MlirAttribute);
220MLIR_CAPI_EXPORTED MlirAttribute hwParamVerbatimAttrGet(MlirAttribute text);
221
222MLIR_CAPI_EXPORTED bool hwAttrIsAOutputFileAttr(MlirAttribute);
223MLIR_CAPI_EXPORTED MlirAttribute hwOutputFileGetFromFileName(
224 MlirAttribute text, bool excludeFromFileList, bool includeReplicatedOp);
225MLIR_CAPI_EXPORTED MlirStringRef
226hwOutputFileGetFileName(MlirAttribute outputFile);
227
228//===----------------------------------------------------------------------===//
229// InstanceGraph API.
230//===----------------------------------------------------------------------===//
231
232MLIR_CAPI_EXPORTED HWInstanceGraph hwInstanceGraphGet(MlirOperation operation);
233
234MLIR_CAPI_EXPORTED void hwInstanceGraphDestroy(HWInstanceGraph instanceGraph);
235
236MLIR_CAPI_EXPORTED HWInstanceGraphNode
237hwInstanceGraphGetTopLevelNode(HWInstanceGraph instanceGraph);
238
239// NOLINTNEXTLINE(modernize-use-using)
240typedef void (*HWInstanceGraphNodeCallback)(HWInstanceGraphNode, void *);
241
242MLIR_CAPI_EXPORTED void
243hwInstanceGraphForEachNode(HWInstanceGraph instanceGraph,
245 void *userData);
246
247MLIR_CAPI_EXPORTED bool hwInstanceGraphNodeEqual(HWInstanceGraphNode lhs,
248 HWInstanceGraphNode rhs);
249
250MLIR_CAPI_EXPORTED MlirModule
251hwInstanceGraphNodeGetModule(HWInstanceGraphNode node);
252
253MLIR_CAPI_EXPORTED MlirOperation
254hwInstanceGraphNodeGetModuleOp(HWInstanceGraphNode node);
255
256#ifdef __cplusplus
257}
258#endif
259
260#endif // CIRCT_C_DIALECT_HW_H
MlirType uint64_t numElements
Definition CHIRRTL.cpp:30
MLIR_CAPI_EXPORTED MlirType hwStructTypeGet(MlirContext ctx, intptr_t numElements, HWStructFieldInfo const *elements)
Creates an HW struct type in the context associated with the elements.
Definition HW.cpp:157
MLIR_CAPI_EXPORTED intptr_t hwModuleTypeGetNumOutputs(MlirType type)
Get an HW module type's number of outputs.
Definition HW.cpp:120
MLIR_CAPI_EXPORTED MlirStringRef hwOutputFileGetFileName(MlirAttribute outputFile)
Definition HW.cpp:373
MLIR_CAPI_EXPORTED MlirType hwParamDeclAttrGetType(MlirAttribute decl)
Definition HW.cpp:326
MLIR_CAPI_EXPORTED MlirAttribute hwOutputFileGetFromFileName(MlirAttribute text, bool excludeFromFileList, bool includeReplicatedOp)
Definition HW.cpp:365
MLIR_CAPI_EXPORTED MlirAttribute hwInnerRefAttrGet(MlirAttribute moduleName, MlirAttribute innerSym)
Definition HW.cpp:297
MLIR_CAPI_EXPORTED bool hwTypeIsAArrayType(MlirType)
If the type is an HW array.
Definition HW.cpp:42
MLIR_CAPI_EXPORTED MlirAttribute hwParamIntTypeGetWidthAttr(MlirType)
Definition HW.cpp:62
MLIR_CAPI_EXPORTED HWInstanceGraphNode hwInstanceGraphGetTopLevelNode(HWInstanceGraph instanceGraph)
Definition HW.cpp:387
MLIR_CAPI_EXPORTED MlirAttribute hwInnerRefAttrGetModule(MlirAttribute)
Definition HW.cpp:308
MLIR_CAPI_EXPORTED MlirOperation hwInstanceGraphNodeGetModuleOp(HWInstanceGraphNode node)
Definition HW.cpp:412
MLIR_CAPI_EXPORTED MlirType hwModuleTypeGetInputType(MlirType type, intptr_t index)
Get an HW module type's input type at a specific index.
Definition HW.cpp:112
MLIR_CAPI_EXPORTED bool hwInstanceGraphNodeEqual(HWInstanceGraphNode lhs, HWInstanceGraphNode rhs)
Definition HW.cpp:401
MLIR_CAPI_EXPORTED int64_t hwGetBitWidth(MlirType)
Return the hardware bit width of a type.
Definition HW.cpp:38
MLIR_CAPI_EXPORTED HWUnionFieldInfo hwUnionTypeGetFieldNum(MlirType unionType, unsigned idx)
Definition HW.cpp:227
MLIR_CAPI_EXPORTED MlirModule hwInstanceGraphNodeGetModule(HWInstanceGraphNode node)
Definition HW.cpp:407
MLIR_CAPI_EXPORTED void registerHWPasses(void)
Definition HW.cpp:32
MLIR_CAPI_EXPORTED HWInstanceGraph hwInstanceGraphGet(MlirOperation operation)
Definition HW.cpp:378
MLIR_CAPI_EXPORTED MlirType hwTypeAliasTypeGet(MlirStringRef scope, MlirStringRef name, MlirType innerType)
Definition HW.cpp:241
MLIR_CAPI_EXPORTED MlirType hwModuleTypeGet(MlirContext ctx, intptr_t numPorts, HWModulePort const *ports)
Creates an HW module type.
Definition HW.cpp:80
MLIR_CAPI_EXPORTED bool hwTypeIsAValueType(MlirType)
Return true if the specified type can be used as an HW value type, that is the set of types that can ...
Definition HW.cpp:40
MLIR_CAPI_EXPORTED MlirAttribute hwInnerSymAttrGetSymName(MlirAttribute)
Definition HW.cpp:289
MLIR_CAPI_EXPORTED MlirAttribute hwStructTypeGetFieldIndex(MlirType structType, MlirStringRef fieldName)
Definition HW.cpp:173
MLIR_CAPI_EXPORTED HWStructFieldInfo hwStructTypeGetFieldNum(MlirType structType, unsigned idx)
Definition HW.cpp:186
HWModulePortDirection
Definition HW.h:42
@ Input
Definition HW.h:42
@ Output
Definition HW.h:42
@ InOut
Definition HW.h:42
MLIR_CAPI_EXPORTED MlirType hwArrayTypeGet(MlirType element, size_t size)
Creates a fixed-size HW array type in the context associated with element.
Definition HW.cpp:44
#define DEFINE_C_API_STRUCT(name, storage)
Definition HW.h:18
MLIR_CAPI_EXPORTED MlirType hwParamIntTypeGet(MlirAttribute parameter)
Definition HW.cpp:58
MLIR_CAPI_EXPORTED MlirAttribute hwParamDeclAttrGetValue(MlirAttribute decl)
Definition HW.cpp:329
MLIR_CAPI_EXPORTED bool hwTypeIsATypeAliasType(MlirType)
If the type is an HW type alias.
Definition HW.cpp:237
MLIR_CAPI_EXPORTED MlirType hwTypeAliasTypeGetCanonicalType(MlirType typeAlias)
Definition HW.cpp:253
void(* HWInstanceGraphNodeCallback)(HWInstanceGraphNode, void *)
Definition HW.h:240
MLIR_CAPI_EXPORTED MlirStringRef hwTypeAliasTypeGetName(MlirType typeAlias)
Definition HW.cpp:263
MLIR_CAPI_EXPORTED intptr_t hwModuleTypeGetNumInputs(MlirType type)
Get an HW module type's number of inputs.
Definition HW.cpp:108
MLIR_CAPI_EXPORTED void hwInstanceGraphDestroy(HWInstanceGraph instanceGraph)
Definition HW.cpp:382
MLIR_CAPI_EXPORTED bool hwTypeIsAIntType(MlirType)
If the type is an HW int.
Definition HW.cpp:56
MLIR_CAPI_EXPORTED void hwInstanceGraphForEachNode(HWInstanceGraph instanceGraph, HWInstanceGraphNodeCallback callback, void *userData)
Definition HW.cpp:392
MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(HW, hw)
MLIR_CAPI_EXPORTED MlirAttribute hwInnerRefAttrGetName(MlirAttribute)
Definition HW.cpp:304
MLIR_CAPI_EXPORTED bool hwAttrIsAInnerRefAttr(MlirAttribute)
Definition HW.cpp:293
MLIR_CAPI_EXPORTED MlirAttribute hwUnionTypeGetFieldIndex(MlirType unionType, MlirStringRef fieldName)
Definition HW.cpp:214
MLIR_CAPI_EXPORTED MlirAttribute hwInnerSymAttrGet(MlirAttribute symName)
Definition HW.cpp:281
MLIR_CAPI_EXPORTED MlirType hwStructTypeGetField(MlirType structType, MlirStringRef fieldName)
Definition HW.cpp:168
MLIR_CAPI_EXPORTED MlirAttribute hwInnerSymAttrGetEmpty(MlirContext ctx)
Definition HW.cpp:285
MLIR_CAPI_EXPORTED void hwModuleTypeGetPort(MlirType type, intptr_t index, HWModulePort *ret)
Get an HW module type's port info at a specific index.
Definition HW.cpp:132
MLIR_CAPI_EXPORTED intptr_t hwUnionTypeGetNumFields(MlirType unionType)
Definition HW.cpp:222
MLIR_CAPI_EXPORTED MlirType hwTypeAliasTypeGetInnerType(MlirType typeAlias)
Definition HW.cpp:258
MLIR_CAPI_EXPORTED MlirStringRef hwModuleTypeGetInputName(MlirType type, intptr_t index)
Get an HW module type's input name at a specific index.
Definition HW.cpp:116
MLIR_CAPI_EXPORTED bool hwAttrIsAParamDeclRefAttr(MlirAttribute)
Definition HW.cpp:333
MLIR_CAPI_EXPORTED bool hwAttrIsAOutputFileAttr(MlirAttribute)
Definition HW.cpp:361
MLIR_CAPI_EXPORTED MlirAttribute hwParamDeclAttrGet(MlirStringRef name, MlirType type, MlirAttribute value)
Definition HW.cpp:315
MLIR_CAPI_EXPORTED MlirType hwUnionTypeGetField(MlirType unionType, MlirStringRef fieldName)
Definition HW.cpp:209
MLIR_CAPI_EXPORTED MlirStringRef hwTypeAliasTypeGetScope(MlirType typeAlias)
Definition HW.cpp:268
MLIR_CAPI_EXPORTED bool hwTypeIsAStructType(MlirType)
If the type is an HW struct.
Definition HW.cpp:153
MLIR_CAPI_EXPORTED bool hwAttrIsAInnerSymAttr(MlirAttribute)
Definition HW.cpp:277
MLIR_CAPI_EXPORTED bool hwTypeIsAInOut(MlirType type)
If the type is an HW inout.
Definition HW.cpp:74
MLIR_CAPI_EXPORTED MlirType hwInOutTypeGetElementType(MlirType)
Returns the element type of an inout type.
Definition HW.cpp:70
MLIR_CAPI_EXPORTED MlirStringRef hwParamDeclRefAttrGetName(MlirAttribute decl)
Definition HW.cpp:344
MLIR_CAPI_EXPORTED MlirStringRef hwModuleTypeGetOutputName(MlirType type, intptr_t index)
Get an HW module type's output name at a specific index.
Definition HW.cpp:128
MLIR_CAPI_EXPORTED MlirType hwUnionTypeGet(MlirContext ctx, intptr_t numElements, HWUnionFieldInfo const *elements)
Creates an HW union type in the context associated with the elements.
Definition HW.cpp:197
MLIR_CAPI_EXPORTED MlirType hwInOutTypeGet(MlirType element)
Creates an HW inout type in the context associated with element.
Definition HW.cpp:66
MLIR_CAPI_EXPORTED MlirType hwArrayTypeGetElementType(MlirType)
returns the element type of an array type
Definition HW.cpp:48
MLIR_CAPI_EXPORTED bool hwAttrIsAParamVerbatimAttr(MlirAttribute)
Definition HW.cpp:351
MLIR_CAPI_EXPORTED bool hwAttrIsAParamDeclAttr(MlirAttribute)
Definition HW.cpp:312
MLIR_CAPI_EXPORTED bool hwTypeIsAModuleType(MlirType type)
If the type is an HW module type.
Definition HW.cpp:76
MLIR_CAPI_EXPORTED MlirAttribute hwParamDeclRefAttrGet(MlirContext ctx, MlirStringRef cName)
Definition HW.cpp:337
MLIR_CAPI_EXPORTED intptr_t hwStructTypeGetNumFields(MlirType structType)
Definition HW.cpp:181
MLIR_CAPI_EXPORTED MlirType hwModuleTypeGetOutputType(MlirType type, intptr_t index)
Get an HW module type's output type at a specific index.
Definition HW.cpp:124
MLIR_CAPI_EXPORTED bool hwTypeIsAUnionType(MlirType)
If the type is an HW union.
Definition HW.cpp:195
MLIR_CAPI_EXPORTED intptr_t hwArrayTypeGetSize(MlirType)
returns the size of an array type
Definition HW.cpp:52
MLIR_CAPI_EXPORTED MlirStringRef hwParamDeclAttrGetName(MlirAttribute decl)
Definition HW.cpp:323
MLIR_CAPI_EXPORTED MlirAttribute hwParamVerbatimAttrGet(MlirAttribute text)
Definition HW.cpp:354
MLIR_CAPI_EXPORTED MlirType hwParamDeclRefAttrGetType(MlirAttribute decl)
Definition HW.cpp:347
Definition hw.py:1
HWModulePortDirection dir
Definition HW.h:48
MlirAttribute name
Definition HW.h:46
MlirType type
Definition HW.h:47
MlirIdentifier name
Definition HW.h:30
MlirType type
Definition HW.h:31
size_t offset
Definition HW.h:38
MlirType type
Definition HW.h:37
MlirIdentifier name
Definition HW.h:36