CIRCT 20.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
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/// Creates an HW struct type in the context associated with the elements.
128MLIR_CAPI_EXPORTED MlirType hwStructTypeGet(MlirContext ctx,
129 intptr_t numElements,
130 HWStructFieldInfo const *elements);
131
132MLIR_CAPI_EXPORTED MlirType hwStructTypeGetField(MlirType structType,
133 MlirStringRef fieldName);
134
135MLIR_CAPI_EXPORTED MlirType hwParamIntTypeGet(MlirAttribute parameter);
136
137MLIR_CAPI_EXPORTED MlirAttribute hwParamIntTypeGetWidthAttr(MlirType);
138
139MLIR_CAPI_EXPORTED MlirAttribute
140hwStructTypeGetFieldIndex(MlirType structType, MlirStringRef fieldName);
141
142MLIR_CAPI_EXPORTED HWStructFieldInfo
143hwStructTypeGetFieldNum(MlirType structType, unsigned idx);
144
145MLIR_CAPI_EXPORTED intptr_t hwStructTypeGetNumFields(MlirType structType);
146
147MLIR_CAPI_EXPORTED MlirType hwTypeAliasTypeGet(MlirStringRef scope,
148 MlirStringRef name,
149 MlirType innerType);
150
151MLIR_CAPI_EXPORTED MlirType hwTypeAliasTypeGetCanonicalType(MlirType typeAlias);
152
153MLIR_CAPI_EXPORTED MlirType hwTypeAliasTypeGetInnerType(MlirType typeAlias);
154
155MLIR_CAPI_EXPORTED MlirStringRef hwTypeAliasTypeGetName(MlirType typeAlias);
156
157MLIR_CAPI_EXPORTED MlirStringRef hwTypeAliasTypeGetScope(MlirType typeAlias);
158
159//===----------------------------------------------------------------------===//
160// Attribute API.
161//===----------------------------------------------------------------------===//
162
163MLIR_CAPI_EXPORTED bool hwAttrIsAInnerSymAttr(MlirAttribute);
164MLIR_CAPI_EXPORTED MlirAttribute hwInnerSymAttrGet(MlirAttribute symName);
165MLIR_CAPI_EXPORTED MlirAttribute hwInnerSymAttrGetEmpty(MlirContext ctx);
166MLIR_CAPI_EXPORTED MlirAttribute hwInnerSymAttrGetSymName(MlirAttribute);
167
168MLIR_CAPI_EXPORTED bool hwAttrIsAInnerRefAttr(MlirAttribute);
169MLIR_CAPI_EXPORTED MlirAttribute hwInnerRefAttrGet(MlirAttribute moduleName,
170 MlirAttribute innerSym);
171MLIR_CAPI_EXPORTED MlirAttribute hwInnerRefAttrGetName(MlirAttribute);
172MLIR_CAPI_EXPORTED MlirAttribute hwInnerRefAttrGetModule(MlirAttribute);
173
174MLIR_CAPI_EXPORTED bool hwAttrIsAParamDeclAttr(MlirAttribute);
175MLIR_CAPI_EXPORTED MlirAttribute hwParamDeclAttrGet(MlirStringRef name,
176 MlirType type,
177 MlirAttribute value);
178MLIR_CAPI_EXPORTED MlirStringRef hwParamDeclAttrGetName(MlirAttribute decl);
179MLIR_CAPI_EXPORTED MlirType hwParamDeclAttrGetType(MlirAttribute decl);
180MLIR_CAPI_EXPORTED MlirAttribute hwParamDeclAttrGetValue(MlirAttribute decl);
181
182MLIR_CAPI_EXPORTED bool hwAttrIsAParamDeclRefAttr(MlirAttribute);
183MLIR_CAPI_EXPORTED MlirAttribute hwParamDeclRefAttrGet(MlirContext ctx,
184 MlirStringRef cName);
185MLIR_CAPI_EXPORTED MlirStringRef hwParamDeclRefAttrGetName(MlirAttribute decl);
186MLIR_CAPI_EXPORTED MlirType hwParamDeclRefAttrGetType(MlirAttribute decl);
187
188MLIR_CAPI_EXPORTED bool hwAttrIsAParamVerbatimAttr(MlirAttribute);
189MLIR_CAPI_EXPORTED MlirAttribute hwParamVerbatimAttrGet(MlirAttribute text);
190
191MLIR_CAPI_EXPORTED bool hwAttrIsAOutputFileAttr(MlirAttribute);
192MLIR_CAPI_EXPORTED MlirAttribute hwOutputFileGetFromFileName(
193 MlirAttribute text, bool excludeFromFileList, bool includeReplicatedOp);
194
195//===----------------------------------------------------------------------===//
196// InstanceGraph API.
197//===----------------------------------------------------------------------===//
198
199MLIR_CAPI_EXPORTED HWInstanceGraph hwInstanceGraphGet(MlirOperation operation);
200
201MLIR_CAPI_EXPORTED void hwInstanceGraphDestroy(HWInstanceGraph instanceGraph);
202
203MLIR_CAPI_EXPORTED HWInstanceGraphNode
204hwInstanceGraphGetTopLevelNode(HWInstanceGraph instanceGraph);
205
206// NOLINTNEXTLINE(modernize-use-using)
207typedef void (*HWInstanceGraphNodeCallback)(HWInstanceGraphNode, void *);
208
209MLIR_CAPI_EXPORTED void
210hwInstanceGraphForEachNode(HWInstanceGraph instanceGraph,
212 void *userData);
213
214MLIR_CAPI_EXPORTED bool hwInstanceGraphNodeEqual(HWInstanceGraphNode lhs,
215 HWInstanceGraphNode rhs);
216
217MLIR_CAPI_EXPORTED MlirModule
218hwInstanceGraphNodeGetModule(HWInstanceGraphNode node);
219
220MLIR_CAPI_EXPORTED MlirOperation
221hwInstanceGraphNodeGetModuleOp(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
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