CIRCT  19.0.0git
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
15 extern "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 
24 DEFINE_C_API_STRUCT(HWInstanceGraph, void);
25 DEFINE_C_API_STRUCT(HWInstanceGraphNode, void);
26 
27 #undef DEFINE_C_API_STRUCT
28 
30  MlirIdentifier name;
31  MlirType type;
32 };
34 
37 
38 struct HWModulePort {
39  MlirAttribute name;
40  MlirType type;
42 };
43 typedef struct HWModulePort HWModulePort;
44 
45 //===----------------------------------------------------------------------===//
46 // Dialect API.
47 //===----------------------------------------------------------------------===//
48 
50 
51 //===----------------------------------------------------------------------===//
52 // Type API.
53 //===----------------------------------------------------------------------===//
54 
55 /// Return the hardware bit width of a type. Does not reflect any encoding,
56 /// padding, or storage scheme, just the bit (and wire width) of a
57 /// statically-size type. Reflects the number of wires needed to transmit a
58 /// value of this type. Returns -1 if the type is not known or cannot be
59 /// statically computed.
60 MLIR_CAPI_EXPORTED int64_t hwGetBitWidth(MlirType);
61 
62 /// Return true if the specified type can be used as an HW value type, that is
63 /// the set of types that can be composed together to represent synthesized,
64 /// hardware but not marker types like InOutType or unknown types from other
65 /// dialects.
66 MLIR_CAPI_EXPORTED bool hwTypeIsAValueType(MlirType);
67 
68 /// If the type is an HW array
69 MLIR_CAPI_EXPORTED bool hwTypeIsAArrayType(MlirType);
70 
71 /// If the type is an HW inout.
72 MLIR_CAPI_EXPORTED bool hwTypeIsAInOut(MlirType type);
73 
74 /// If the type is an HW module type.
75 MLIR_CAPI_EXPORTED bool hwTypeIsAModuleType(MlirType type);
76 
77 /// If the type is an HW struct.
78 MLIR_CAPI_EXPORTED bool hwTypeIsAStructType(MlirType);
79 
80 /// If the type is an HW type alias.
81 MLIR_CAPI_EXPORTED bool hwTypeIsATypeAliasType(MlirType);
82 
83 /// If the type is an HW int.
84 MLIR_CAPI_EXPORTED bool hwTypeIsAIntType(MlirType);
85 
86 /// Creates a fixed-size HW array type in the context associated with element
87 MLIR_CAPI_EXPORTED MlirType hwArrayTypeGet(MlirType element, size_t size);
88 
89 /// returns the element type of an array type
90 MLIR_CAPI_EXPORTED MlirType hwArrayTypeGetElementType(MlirType);
91 
92 /// returns the size of an array type
93 MLIR_CAPI_EXPORTED intptr_t hwArrayTypeGetSize(MlirType);
94 
95 /// Creates an HW inout type in the context associated with element.
96 MLIR_CAPI_EXPORTED MlirType hwInOutTypeGet(MlirType element);
97 
98 /// Returns the element type of an inout type.
99 MLIR_CAPI_EXPORTED MlirType hwInOutTypeGetElementType(MlirType);
100 
101 /// Creates an HW module type.
102 MLIR_CAPI_EXPORTED MlirType hwModuleTypeGet(MlirContext ctx, intptr_t numPorts,
103  HWModulePort const *ports);
104 
105 /// Get an HW module type's number of inputs.
106 MLIR_CAPI_EXPORTED intptr_t hwModuleTypeGetNumInputs(MlirType type);
107 
108 /// Get an HW module type's input type at a specific index.
109 MLIR_CAPI_EXPORTED MlirType hwModuleTypeGetInputType(MlirType type,
110  intptr_t index);
111 
112 /// Get an HW module type's input name at a specific index.
113 MLIR_CAPI_EXPORTED MlirStringRef hwModuleTypeGetInputName(MlirType type,
114  intptr_t index);
115 
116 /// Get an HW module type's number of outputs.
117 MLIR_CAPI_EXPORTED intptr_t hwModuleTypeGetNumOutputs(MlirType type);
118 
119 /// Get an HW module type's output type at a specific index.
120 MLIR_CAPI_EXPORTED MlirType hwModuleTypeGetOutputType(MlirType type,
121  intptr_t index);
122 
123 /// Get an HW module type's output name at a specific index.
124 MLIR_CAPI_EXPORTED MlirStringRef hwModuleTypeGetOutputName(MlirType type,
125  intptr_t index);
126 /// Creates an HW struct type in the context associated with the elements.
127 MLIR_CAPI_EXPORTED MlirType hwStructTypeGet(MlirContext ctx,
128  intptr_t numElements,
129  HWStructFieldInfo const *elements);
130 
131 MLIR_CAPI_EXPORTED MlirType hwStructTypeGetField(MlirType structType,
132  MlirStringRef fieldName);
133 
134 MLIR_CAPI_EXPORTED MlirType hwParamIntTypeGet(MlirAttribute parameter);
135 
136 MLIR_CAPI_EXPORTED MlirAttribute hwParamIntTypeGetWidthAttr(MlirType);
137 
138 MLIR_CAPI_EXPORTED MlirAttribute
139 hwStructTypeGetFieldIndex(MlirType structType, MlirStringRef fieldName);
140 
141 MLIR_CAPI_EXPORTED HWStructFieldInfo
142 hwStructTypeGetFieldNum(MlirType structType, unsigned idx);
143 
144 MLIR_CAPI_EXPORTED intptr_t hwStructTypeGetNumFields(MlirType structType);
145 
146 MLIR_CAPI_EXPORTED MlirType hwTypeAliasTypeGet(MlirStringRef scope,
147  MlirStringRef name,
148  MlirType innerType);
149 
150 MLIR_CAPI_EXPORTED MlirType hwTypeAliasTypeGetCanonicalType(MlirType typeAlias);
151 
152 MLIR_CAPI_EXPORTED MlirType hwTypeAliasTypeGetInnerType(MlirType typeAlias);
153 
154 MLIR_CAPI_EXPORTED MlirStringRef hwTypeAliasTypeGetName(MlirType typeAlias);
155 
156 MLIR_CAPI_EXPORTED MlirStringRef hwTypeAliasTypeGetScope(MlirType typeAlias);
157 
158 //===----------------------------------------------------------------------===//
159 // Attribute API.
160 //===----------------------------------------------------------------------===//
161 
162 MLIR_CAPI_EXPORTED bool hwAttrIsAInnerSymAttr(MlirAttribute);
163 MLIR_CAPI_EXPORTED MlirAttribute hwInnerSymAttrGet(MlirAttribute symName);
164 MLIR_CAPI_EXPORTED MlirAttribute hwInnerSymAttrGetSymName(MlirAttribute);
165 
166 MLIR_CAPI_EXPORTED bool hwAttrIsAInnerRefAttr(MlirAttribute);
167 MLIR_CAPI_EXPORTED MlirAttribute hwInnerRefAttrGet(MlirAttribute moduleName,
168  MlirAttribute innerSym);
169 MLIR_CAPI_EXPORTED MlirAttribute hwInnerRefAttrGetName(MlirAttribute);
170 MLIR_CAPI_EXPORTED MlirAttribute hwInnerRefAttrGetModule(MlirAttribute);
171 
172 MLIR_CAPI_EXPORTED bool hwAttrIsAParamDeclAttr(MlirAttribute);
173 MLIR_CAPI_EXPORTED MlirAttribute hwParamDeclAttrGet(MlirStringRef name,
174  MlirType type,
175  MlirAttribute value);
176 MLIR_CAPI_EXPORTED MlirStringRef hwParamDeclAttrGetName(MlirAttribute decl);
177 MLIR_CAPI_EXPORTED MlirType hwParamDeclAttrGetType(MlirAttribute decl);
178 MLIR_CAPI_EXPORTED MlirAttribute hwParamDeclAttrGetValue(MlirAttribute decl);
179 
180 MLIR_CAPI_EXPORTED bool hwAttrIsAParamDeclRefAttr(MlirAttribute);
181 MLIR_CAPI_EXPORTED MlirAttribute hwParamDeclRefAttrGet(MlirContext ctx,
182  MlirStringRef cName);
183 MLIR_CAPI_EXPORTED MlirStringRef hwParamDeclRefAttrGetName(MlirAttribute decl);
184 MLIR_CAPI_EXPORTED MlirType hwParamDeclRefAttrGetType(MlirAttribute decl);
185 
186 MLIR_CAPI_EXPORTED bool hwAttrIsAParamVerbatimAttr(MlirAttribute);
187 MLIR_CAPI_EXPORTED MlirAttribute hwParamVerbatimAttrGet(MlirAttribute text);
188 
189 MLIR_CAPI_EXPORTED bool hwAttrIsAOutputFileAttr(MlirAttribute);
190 MLIR_CAPI_EXPORTED MlirAttribute hwOutputFileGetFromFileName(
191  MlirAttribute text, bool excludeFromFileList, bool includeReplicatedOp);
192 
193 //===----------------------------------------------------------------------===//
194 // InstanceGraph API.
195 //===----------------------------------------------------------------------===//
196 
197 MLIR_CAPI_EXPORTED HWInstanceGraph hwInstanceGraphGet(MlirOperation operation);
198 
199 MLIR_CAPI_EXPORTED void hwInstanceGraphDestroy(HWInstanceGraph instanceGraph);
200 
201 MLIR_CAPI_EXPORTED HWInstanceGraphNode
202 hwInstanceGraphGetTopLevelNode(HWInstanceGraph instanceGraph);
203 
204 // NOLINTNEXTLINE(modernize-use-using)
205 typedef void (*HWInstanceGraphNodeCallback)(HWInstanceGraphNode, void *);
206 
207 MLIR_CAPI_EXPORTED void
208 hwInstanceGraphForEachNode(HWInstanceGraph instanceGraph,
210  void *userData);
211 
212 MLIR_CAPI_EXPORTED bool hwInstanceGraphNodeEqual(HWInstanceGraphNode lhs,
213  HWInstanceGraphNode rhs);
214 
215 MLIR_CAPI_EXPORTED MlirModule
216 hwInstanceGraphNodeGetModule(HWInstanceGraphNode node);
217 
218 MLIR_CAPI_EXPORTED MlirOperation
219 hwInstanceGraphNodeGetModuleOp(HWInstanceGraphNode node);
220 
221 #ifdef __cplusplus
222 }
223 #endif
224 
225 #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:134
MLIR_CAPI_EXPORTED intptr_t hwModuleTypeGetNumOutputs(MlirType type)
Get an HW module type's number of outputs.
Definition: HW.cpp:118
MLIR_CAPI_EXPORTED MlirType hwParamDeclAttrGetType(MlirAttribute decl)
Definition: HW.cpp:258
MLIR_CAPI_EXPORTED MlirAttribute hwOutputFileGetFromFileName(MlirAttribute text, bool excludeFromFileList, bool includeReplicatedOp)
Definition: HW.cpp:297
MLIR_CAPI_EXPORTED MlirAttribute hwInnerRefAttrGet(MlirAttribute moduleName, MlirAttribute innerSym)
Definition: HW.cpp:229
MLIR_CAPI_EXPORTED bool hwTypeIsAArrayType(MlirType)
If the type is an HW array.
Definition: HW.cpp:40
MLIR_CAPI_EXPORTED MlirAttribute hwParamIntTypeGetWidthAttr(MlirType)
Definition: HW.cpp:60
MLIR_CAPI_EXPORTED HWInstanceGraphNode hwInstanceGraphGetTopLevelNode(HWInstanceGraph instanceGraph)
Definition: HW.cpp:314
MLIR_CAPI_EXPORTED MlirAttribute hwInnerRefAttrGetModule(MlirAttribute)
Definition: HW.cpp:240
MLIR_CAPI_EXPORTED MlirOperation hwInstanceGraphNodeGetModuleOp(HWInstanceGraphNode node)
Definition: HW.cpp:339
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:110
MLIR_CAPI_EXPORTED bool hwInstanceGraphNodeEqual(HWInstanceGraphNode lhs, HWInstanceGraphNode rhs)
Definition: HW.cpp:328
MLIR_CAPI_EXPORTED int64_t hwGetBitWidth(MlirType)
Return the hardware bit width of a type.
Definition: HW.cpp:36
MLIR_CAPI_EXPORTED MlirModule hwInstanceGraphNodeGetModule(HWInstanceGraphNode node)
Definition: HW.cpp:334
MLIR_CAPI_EXPORTED HWInstanceGraph hwInstanceGraphGet(MlirOperation operation)
Definition: HW.cpp:305
MLIR_CAPI_EXPORTED MlirType hwTypeAliasTypeGet(MlirStringRef scope, MlirStringRef name, MlirType innerType)
Definition: HW.cpp:176
MLIR_CAPI_EXPORTED MlirType hwModuleTypeGet(MlirContext ctx, intptr_t numPorts, HWModulePort const *ports)
Creates an HW module type.
Definition: HW.cpp:78
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:38
MLIR_CAPI_EXPORTED MlirAttribute hwInnerSymAttrGetSymName(MlirAttribute)
Definition: HW.cpp:220
MLIR_CAPI_EXPORTED MlirAttribute hwStructTypeGetFieldIndex(MlirType structType, MlirStringRef fieldName)
Definition: HW.cpp:150
MLIR_CAPI_EXPORTED HWStructFieldInfo hwStructTypeGetFieldNum(MlirType structType, unsigned idx)
Definition: HW.cpp:163
HWModulePortDirection
Definition: HW.h:35
@ Input
Definition: HW.h:35
@ Output
Definition: HW.h:35
@ InOut
Definition: HW.h:35
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:42
#define DEFINE_C_API_STRUCT(name, storage)
Definition: HW.h:18
MLIR_CAPI_EXPORTED MlirType hwParamIntTypeGet(MlirAttribute parameter)
Definition: HW.cpp:56
MLIR_CAPI_EXPORTED MlirAttribute hwParamDeclAttrGetValue(MlirAttribute decl)
Definition: HW.cpp:261
MLIR_CAPI_EXPORTED bool hwTypeIsATypeAliasType(MlirType)
If the type is an HW type alias.
Definition: HW.cpp:172
MLIR_CAPI_EXPORTED MlirType hwTypeAliasTypeGetCanonicalType(MlirType typeAlias)
Definition: HW.cpp:188
void(* HWInstanceGraphNodeCallback)(HWInstanceGraphNode, void *)
Definition: HW.h:205
MLIR_CAPI_EXPORTED MlirStringRef hwTypeAliasTypeGetName(MlirType typeAlias)
Definition: HW.cpp:198
MLIR_CAPI_EXPORTED intptr_t hwModuleTypeGetNumInputs(MlirType type)
Get an HW module type's number of inputs.
Definition: HW.cpp:106
MLIR_CAPI_EXPORTED void hwInstanceGraphDestroy(HWInstanceGraph instanceGraph)
Definition: HW.cpp:309
MLIR_CAPI_EXPORTED bool hwTypeIsAIntType(MlirType)
If the type is an HW int.
Definition: HW.cpp:54
MLIR_CAPI_EXPORTED void hwInstanceGraphForEachNode(HWInstanceGraph instanceGraph, HWInstanceGraphNodeCallback callback, void *userData)
Definition: HW.cpp:319
MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(HW, hw)
MLIR_CAPI_EXPORTED MlirAttribute hwInnerRefAttrGetName(MlirAttribute)
Definition: HW.cpp:236
MLIR_CAPI_EXPORTED bool hwAttrIsAInnerRefAttr(MlirAttribute)
Definition: HW.cpp:225
MLIR_CAPI_EXPORTED MlirAttribute hwInnerSymAttrGet(MlirAttribute symName)
Definition: HW.cpp:216
MLIR_CAPI_EXPORTED MlirType hwStructTypeGetField(MlirType structType, MlirStringRef fieldName)
Definition: HW.cpp:145
MLIR_CAPI_EXPORTED MlirType hwTypeAliasTypeGetInnerType(MlirType typeAlias)
Definition: HW.cpp:193
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:114
MLIR_CAPI_EXPORTED bool hwAttrIsAParamDeclRefAttr(MlirAttribute)
Definition: HW.cpp:265
MLIR_CAPI_EXPORTED bool hwAttrIsAOutputFileAttr(MlirAttribute)
Definition: HW.cpp:293
MLIR_CAPI_EXPORTED MlirAttribute hwParamDeclAttrGet(MlirStringRef name, MlirType type, MlirAttribute value)
Definition: HW.cpp:247
MLIR_CAPI_EXPORTED MlirStringRef hwTypeAliasTypeGetScope(MlirType typeAlias)
Definition: HW.cpp:203
MLIR_CAPI_EXPORTED bool hwTypeIsAStructType(MlirType)
If the type is an HW struct.
Definition: HW.cpp:130
MLIR_CAPI_EXPORTED bool hwAttrIsAInnerSymAttr(MlirAttribute)
Definition: HW.cpp:212
MLIR_CAPI_EXPORTED bool hwTypeIsAInOut(MlirType type)
If the type is an HW inout.
Definition: HW.cpp:72
MLIR_CAPI_EXPORTED MlirType hwInOutTypeGetElementType(MlirType)
Returns the element type of an inout type.
Definition: HW.cpp:68
MLIR_CAPI_EXPORTED MlirStringRef hwParamDeclRefAttrGetName(MlirAttribute decl)
Definition: HW.cpp:276
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:126
MLIR_CAPI_EXPORTED MlirType hwInOutTypeGet(MlirType element)
Creates an HW inout type in the context associated with element.
Definition: HW.cpp:64
MLIR_CAPI_EXPORTED MlirType hwArrayTypeGetElementType(MlirType)
returns the element type of an array type
Definition: HW.cpp:46
MLIR_CAPI_EXPORTED bool hwAttrIsAParamVerbatimAttr(MlirAttribute)
Definition: HW.cpp:283
MLIR_CAPI_EXPORTED bool hwAttrIsAParamDeclAttr(MlirAttribute)
Definition: HW.cpp:244
MLIR_CAPI_EXPORTED bool hwTypeIsAModuleType(MlirType type)
If the type is an HW module type.
Definition: HW.cpp:74
MLIR_CAPI_EXPORTED MlirAttribute hwParamDeclRefAttrGet(MlirContext ctx, MlirStringRef cName)
Definition: HW.cpp:269
MLIR_CAPI_EXPORTED intptr_t hwStructTypeGetNumFields(MlirType structType)
Definition: HW.cpp:158
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:122
MLIR_CAPI_EXPORTED intptr_t hwArrayTypeGetSize(MlirType)
returns the size of an array type
Definition: HW.cpp:50
MLIR_CAPI_EXPORTED MlirStringRef hwParamDeclAttrGetName(MlirAttribute decl)
Definition: HW.cpp:255
MLIR_CAPI_EXPORTED MlirAttribute hwParamVerbatimAttrGet(MlirAttribute text)
Definition: HW.cpp:286
MLIR_CAPI_EXPORTED MlirType hwParamDeclRefAttrGetType(MlirAttribute decl)
Definition: HW.cpp:279
mlir::Type innerType(mlir::Type type)
Definition: ESITypes.cpp:184
Definition: hw.py:1
HWModulePortDirection dir
Definition: HW.h:41
MlirAttribute name
Definition: HW.h:39
MlirType type
Definition: HW.h:40
MlirIdentifier name
Definition: HW.h:30
MlirType type
Definition: HW.h:31