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