Loading [MathJax]/extensions/tex2jax.js
CIRCT 22.0.0git
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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
37
39 MlirAttribute name;
40 MlirType type;
42};
44
45//===----------------------------------------------------------------------===//
46// Dialect API.
47//===----------------------------------------------------------------------===//
48
50MLIR_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.
61MLIR_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.
67MLIR_CAPI_EXPORTED bool hwTypeIsAValueType(MlirType);
68
69/// If the type is an HW array
70MLIR_CAPI_EXPORTED bool hwTypeIsAArrayType(MlirType);
71
72/// If the type is an HW inout.
73MLIR_CAPI_EXPORTED bool hwTypeIsAInOut(MlirType type);
74
75/// If the type is an HW module type.
76MLIR_CAPI_EXPORTED bool hwTypeIsAModuleType(MlirType type);
77
78/// If the type is an HW struct.
79MLIR_CAPI_EXPORTED bool hwTypeIsAStructType(MlirType);
80
81/// If the type is an HW type alias.
82MLIR_CAPI_EXPORTED bool hwTypeIsATypeAliasType(MlirType);
83
84/// If the type is an HW int.
85MLIR_CAPI_EXPORTED bool hwTypeIsAIntType(MlirType);
86
87/// Creates a fixed-size HW array type in the context associated with element
88MLIR_CAPI_EXPORTED MlirType hwArrayTypeGet(MlirType element, size_t size);
89
90/// returns the element type of an array type
91MLIR_CAPI_EXPORTED MlirType hwArrayTypeGetElementType(MlirType);
92
93/// returns the size of an array type
94MLIR_CAPI_EXPORTED intptr_t hwArrayTypeGetSize(MlirType);
95
96/// Creates an HW inout type in the context associated with element.
97MLIR_CAPI_EXPORTED MlirType hwInOutTypeGet(MlirType element);
98
99/// Returns the element type of an inout type.
100MLIR_CAPI_EXPORTED MlirType hwInOutTypeGetElementType(MlirType);
101
102/// Creates an HW module type.
103MLIR_CAPI_EXPORTED MlirType hwModuleTypeGet(MlirContext ctx, intptr_t numPorts,
104 HWModulePort const *ports);
105
106/// Get an HW module type's number of inputs.
107MLIR_CAPI_EXPORTED intptr_t hwModuleTypeGetNumInputs(MlirType type);
108
109/// Get an HW module type's input type at a specific index.
110MLIR_CAPI_EXPORTED MlirType hwModuleTypeGetInputType(MlirType type,
111 intptr_t index);
112
113/// Get an HW module type's input name at a specific index.
114MLIR_CAPI_EXPORTED MlirStringRef hwModuleTypeGetInputName(MlirType type,
115 intptr_t index);
116
117/// Get an HW module type's number of outputs.
118MLIR_CAPI_EXPORTED intptr_t hwModuleTypeGetNumOutputs(MlirType type);
119
120/// Get an HW module type's output type at a specific index.
121MLIR_CAPI_EXPORTED MlirType hwModuleTypeGetOutputType(MlirType type,
122 intptr_t index);
123
124/// Get an HW module type's output name at a specific index.
125MLIR_CAPI_EXPORTED MlirStringRef hwModuleTypeGetOutputName(MlirType type,
126 intptr_t index);
127
128/// Get an HW module type's port info at a specific index.
129MLIR_CAPI_EXPORTED void hwModuleTypeGetPort(MlirType type, intptr_t index,
130 HWModulePort *ret);
131
132/// Creates an HW struct type in the context associated with the elements.
133MLIR_CAPI_EXPORTED MlirType hwStructTypeGet(MlirContext ctx,
134 intptr_t numElements,
135 HWStructFieldInfo const *elements);
136
137MLIR_CAPI_EXPORTED MlirType hwStructTypeGetField(MlirType structType,
138 MlirStringRef fieldName);
139
140MLIR_CAPI_EXPORTED MlirType hwParamIntTypeGet(MlirAttribute parameter);
141
142MLIR_CAPI_EXPORTED MlirAttribute hwParamIntTypeGetWidthAttr(MlirType);
143
144MLIR_CAPI_EXPORTED MlirAttribute
145hwStructTypeGetFieldIndex(MlirType structType, MlirStringRef fieldName);
146
147MLIR_CAPI_EXPORTED HWStructFieldInfo
148hwStructTypeGetFieldNum(MlirType structType, unsigned idx);
149
150MLIR_CAPI_EXPORTED intptr_t hwStructTypeGetNumFields(MlirType structType);
151
152MLIR_CAPI_EXPORTED MlirType hwTypeAliasTypeGet(MlirStringRef scope,
153 MlirStringRef name,
154 MlirType innerType);
155
156MLIR_CAPI_EXPORTED MlirType hwTypeAliasTypeGetCanonicalType(MlirType typeAlias);
157
158MLIR_CAPI_EXPORTED MlirType hwTypeAliasTypeGetInnerType(MlirType typeAlias);
159
160MLIR_CAPI_EXPORTED MlirStringRef hwTypeAliasTypeGetName(MlirType typeAlias);
161
162MLIR_CAPI_EXPORTED MlirStringRef hwTypeAliasTypeGetScope(MlirType typeAlias);
163
164//===----------------------------------------------------------------------===//
165// Attribute API.
166//===----------------------------------------------------------------------===//
167
168MLIR_CAPI_EXPORTED bool hwAttrIsAInnerSymAttr(MlirAttribute);
169MLIR_CAPI_EXPORTED MlirAttribute hwInnerSymAttrGet(MlirAttribute symName);
170MLIR_CAPI_EXPORTED MlirAttribute hwInnerSymAttrGetEmpty(MlirContext ctx);
171MLIR_CAPI_EXPORTED MlirAttribute hwInnerSymAttrGetSymName(MlirAttribute);
172
173MLIR_CAPI_EXPORTED bool hwAttrIsAInnerRefAttr(MlirAttribute);
174MLIR_CAPI_EXPORTED MlirAttribute hwInnerRefAttrGet(MlirAttribute moduleName,
175 MlirAttribute innerSym);
176MLIR_CAPI_EXPORTED MlirAttribute hwInnerRefAttrGetName(MlirAttribute);
177MLIR_CAPI_EXPORTED MlirAttribute hwInnerRefAttrGetModule(MlirAttribute);
178
179MLIR_CAPI_EXPORTED bool hwAttrIsAParamDeclAttr(MlirAttribute);
180MLIR_CAPI_EXPORTED MlirAttribute hwParamDeclAttrGet(MlirStringRef name,
181 MlirType type,
182 MlirAttribute value);
183MLIR_CAPI_EXPORTED MlirStringRef hwParamDeclAttrGetName(MlirAttribute decl);
184MLIR_CAPI_EXPORTED MlirType hwParamDeclAttrGetType(MlirAttribute decl);
185MLIR_CAPI_EXPORTED MlirAttribute hwParamDeclAttrGetValue(MlirAttribute decl);
186
187MLIR_CAPI_EXPORTED bool hwAttrIsAParamDeclRefAttr(MlirAttribute);
188MLIR_CAPI_EXPORTED MlirAttribute hwParamDeclRefAttrGet(MlirContext ctx,
189 MlirStringRef cName);
190MLIR_CAPI_EXPORTED MlirStringRef hwParamDeclRefAttrGetName(MlirAttribute decl);
191MLIR_CAPI_EXPORTED MlirType hwParamDeclRefAttrGetType(MlirAttribute decl);
192
193MLIR_CAPI_EXPORTED bool hwAttrIsAParamVerbatimAttr(MlirAttribute);
194MLIR_CAPI_EXPORTED MlirAttribute hwParamVerbatimAttrGet(MlirAttribute text);
195
196MLIR_CAPI_EXPORTED bool hwAttrIsAOutputFileAttr(MlirAttribute);
197MLIR_CAPI_EXPORTED MlirAttribute hwOutputFileGetFromFileName(
198 MlirAttribute text, bool excludeFromFileList, bool includeReplicatedOp);
199MLIR_CAPI_EXPORTED MlirStringRef
200hwOutputFileGetFileName(MlirAttribute outputFile);
201
202//===----------------------------------------------------------------------===//
203// InstanceGraph API.
204//===----------------------------------------------------------------------===//
205
206MLIR_CAPI_EXPORTED HWInstanceGraph hwInstanceGraphGet(MlirOperation operation);
207
208MLIR_CAPI_EXPORTED void hwInstanceGraphDestroy(HWInstanceGraph instanceGraph);
209
210MLIR_CAPI_EXPORTED HWInstanceGraphNode
211hwInstanceGraphGetTopLevelNode(HWInstanceGraph instanceGraph);
212
213// NOLINTNEXTLINE(modernize-use-using)
214typedef void (*HWInstanceGraphNodeCallback)(HWInstanceGraphNode, void *);
215
216MLIR_CAPI_EXPORTED void
217hwInstanceGraphForEachNode(HWInstanceGraph instanceGraph,
219 void *userData);
220
221MLIR_CAPI_EXPORTED bool hwInstanceGraphNodeEqual(HWInstanceGraphNode lhs,
222 HWInstanceGraphNode rhs);
223
224MLIR_CAPI_EXPORTED MlirModule
225hwInstanceGraphNodeGetModule(HWInstanceGraphNode node);
226
227MLIR_CAPI_EXPORTED MlirOperation
228hwInstanceGraphNodeGetModuleOp(HWInstanceGraphNode node);
229
230#ifdef __cplusplus
231}
232#endif
233
234#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:331
MLIR_CAPI_EXPORTED MlirType hwParamDeclAttrGetType(MlirAttribute decl)
Definition HW.cpp:284
MLIR_CAPI_EXPORTED MlirAttribute hwOutputFileGetFromFileName(MlirAttribute text, bool excludeFromFileList, bool includeReplicatedOp)
Definition HW.cpp:323
MLIR_CAPI_EXPORTED MlirAttribute hwInnerRefAttrGet(MlirAttribute moduleName, MlirAttribute innerSym)
Definition HW.cpp:255
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:345
MLIR_CAPI_EXPORTED MlirAttribute hwInnerRefAttrGetModule(MlirAttribute)
Definition HW.cpp:266
MLIR_CAPI_EXPORTED MlirOperation hwInstanceGraphNodeGetModuleOp(HWInstanceGraphNode node)
Definition HW.cpp:370
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:359
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:365
MLIR_CAPI_EXPORTED void registerHWPasses(void)
Definition HW.cpp:32
MLIR_CAPI_EXPORTED HWInstanceGraph hwInstanceGraphGet(MlirOperation operation)
Definition HW.cpp:336
MLIR_CAPI_EXPORTED MlirType hwTypeAliasTypeGet(MlirStringRef scope, MlirStringRef name, MlirType innerType)
Definition HW.cpp:199
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:247
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: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:287
MLIR_CAPI_EXPORTED bool hwTypeIsATypeAliasType(MlirType)
If the type is an HW type alias.
Definition HW.cpp:195
MLIR_CAPI_EXPORTED MlirType hwTypeAliasTypeGetCanonicalType(MlirType typeAlias)
Definition HW.cpp:211
void(* HWInstanceGraphNodeCallback)(HWInstanceGraphNode, void *)
Definition HW.h:214
MLIR_CAPI_EXPORTED MlirStringRef hwTypeAliasTypeGetName(MlirType typeAlias)
Definition HW.cpp:221
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:340
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:350
MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(HW, hw)
MLIR_CAPI_EXPORTED MlirAttribute hwInnerRefAttrGetName(MlirAttribute)
Definition HW.cpp:262
MLIR_CAPI_EXPORTED bool hwAttrIsAInnerRefAttr(MlirAttribute)
Definition HW.cpp:251
MLIR_CAPI_EXPORTED MlirAttribute hwInnerSymAttrGet(MlirAttribute symName)
Definition HW.cpp:239
MLIR_CAPI_EXPORTED MlirType hwStructTypeGetField(MlirType structType, MlirStringRef fieldName)
Definition HW.cpp:168
MLIR_CAPI_EXPORTED MlirAttribute hwInnerSymAttrGetEmpty(MlirContext ctx)
Definition HW.cpp:243
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 MlirType hwTypeAliasTypeGetInnerType(MlirType typeAlias)
Definition HW.cpp:216
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:291
MLIR_CAPI_EXPORTED bool hwAttrIsAOutputFileAttr(MlirAttribute)
Definition HW.cpp:319
MLIR_CAPI_EXPORTED MlirAttribute hwParamDeclAttrGet(MlirStringRef name, MlirType type, MlirAttribute value)
Definition HW.cpp:273
MLIR_CAPI_EXPORTED MlirStringRef hwTypeAliasTypeGetScope(MlirType typeAlias)
Definition HW.cpp:226
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:235
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:302
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:309
MLIR_CAPI_EXPORTED bool hwAttrIsAParamDeclAttr(MlirAttribute)
Definition HW.cpp:270
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:295
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 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:281
MLIR_CAPI_EXPORTED MlirAttribute hwParamVerbatimAttrGet(MlirAttribute text)
Definition HW.cpp:312
MLIR_CAPI_EXPORTED MlirType hwParamDeclRefAttrGetType(MlirAttribute decl)
Definition HW.cpp:305
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