CIRCT  18.0.0git
HW.h
Go to the documentation of this file.
1 //===-- circt-c/Dialect/HW.h - C API for 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 // This header declares the C interface for registering and accessing the
10 // HW dialect. A dialect should be registered with a context to make it
11 // available to users of the context. These users must load the dialect
12 // before using any of its attributes, operations or types. Parser and pass
13 // manager can load registered dialects automatically.
14 //
15 //===----------------------------------------------------------------------===//
16 
17 #ifndef CIRCT_C_DIALECT_HW_H
18 #define CIRCT_C_DIALECT_HW_H
19 
20 #include "mlir-c/IR.h"
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
27  MlirIdentifier name;
28  MlirType type;
29 };
31 
34 
35 struct HWModulePort {
36  MlirAttribute name;
37  MlirType type;
39 };
40 typedef struct HWModulePort HWModulePort;
41 
42 //===----------------------------------------------------------------------===//
43 // Dialect API.
44 //===----------------------------------------------------------------------===//
45 
47 
48 //===----------------------------------------------------------------------===//
49 // Type API.
50 //===----------------------------------------------------------------------===//
51 
52 /// Return the hardware bit width of a type. Does not reflect any encoding,
53 /// padding, or storage scheme, just the bit (and wire width) of a
54 /// statically-size type. Reflects the number of wires needed to transmit a
55 /// value of this type. Returns -1 if the type is not known or cannot be
56 /// statically computed.
57 MLIR_CAPI_EXPORTED int64_t hwGetBitWidth(MlirType);
58 
59 /// Return true if the specified type can be used as an HW value type, that is
60 /// the set of types that can be composed together to represent synthesized,
61 /// hardware but not marker types like InOutType or unknown types from other
62 /// dialects.
63 MLIR_CAPI_EXPORTED bool hwTypeIsAValueType(MlirType);
64 
65 /// If the type is an HW array
66 MLIR_CAPI_EXPORTED bool hwTypeIsAArrayType(MlirType);
67 
68 /// If the type is an HW inout.
69 MLIR_CAPI_EXPORTED bool hwTypeIsAInOut(MlirType type);
70 
71 /// If the type is an HW module type.
72 MLIR_CAPI_EXPORTED bool hwTypeIsAModuleType(MlirType type);
73 
74 /// If the type is an HW struct.
75 MLIR_CAPI_EXPORTED bool hwTypeIsAStructType(MlirType);
76 
77 /// If the type is an HW type alias.
78 MLIR_CAPI_EXPORTED bool hwTypeIsATypeAliasType(MlirType);
79 
80 /// If the type is an HW int.
81 MLIR_CAPI_EXPORTED bool hwTypeIsAIntType(MlirType);
82 
83 /// Creates a fixed-size HW array type in the context associated with element
84 MLIR_CAPI_EXPORTED MlirType hwArrayTypeGet(MlirType element, size_t size);
85 
86 /// returns the element type of an array type
87 MLIR_CAPI_EXPORTED MlirType hwArrayTypeGetElementType(MlirType);
88 
89 /// returns the size of an array type
90 MLIR_CAPI_EXPORTED intptr_t hwArrayTypeGetSize(MlirType);
91 
92 /// Creates an HW inout type in the context associated with element.
93 MLIR_CAPI_EXPORTED MlirType hwInOutTypeGet(MlirType element);
94 
95 /// Returns the element type of an inout type.
96 MLIR_CAPI_EXPORTED MlirType hwInOutTypeGetElementType(MlirType);
97 
98 /// Creates an HW module type.
99 MLIR_CAPI_EXPORTED MlirType hwModuleTypeGet(MlirContext ctx, intptr_t numPorts,
100  HWModulePort const *ports);
101 
102 /// Get an HW module type's number of inputs.
103 MLIR_CAPI_EXPORTED intptr_t hwModuleTypeGetNumInputs(MlirType type);
104 
105 /// Get an HW module type's input type at a specific index.
106 MLIR_CAPI_EXPORTED MlirType hwModuleTypeGetInputType(MlirType type,
107  intptr_t index);
108 
109 /// Get an HW module type's input name at a specific index.
110 MLIR_CAPI_EXPORTED MlirStringRef hwModuleTypeGetInputName(MlirType type,
111  intptr_t index);
112 
113 /// Get an HW module type's number of outputs.
114 MLIR_CAPI_EXPORTED intptr_t hwModuleTypeGetNumOutputs(MlirType type);
115 
116 /// Get an HW module type's output type at a specific index.
117 MLIR_CAPI_EXPORTED MlirType hwModuleTypeGetOutputType(MlirType type,
118  intptr_t index);
119 
120 /// Get an HW module type's output name at a specific index.
121 MLIR_CAPI_EXPORTED MlirStringRef hwModuleTypeGetOutputName(MlirType type,
122  intptr_t index);
123 /// Creates an HW struct type in the context associated with the elements.
124 MLIR_CAPI_EXPORTED MlirType hwStructTypeGet(MlirContext ctx,
125  intptr_t numElements,
126  HWStructFieldInfo const *elements);
127 
128 MLIR_CAPI_EXPORTED MlirType hwStructTypeGetField(MlirType structType,
129  MlirStringRef fieldName);
130 
131 MLIR_CAPI_EXPORTED MlirType hwParamIntTypeGet(MlirAttribute parameter);
132 
133 MLIR_CAPI_EXPORTED MlirAttribute hwParamIntTypeGetWidthAttr(MlirType);
134 
135 MLIR_CAPI_EXPORTED MlirAttribute
136 hwStructTypeGetFieldIndex(MlirType structType, MlirStringRef fieldName);
137 
138 MLIR_CAPI_EXPORTED HWStructFieldInfo
139 hwStructTypeGetFieldNum(MlirType structType, unsigned idx);
140 
141 MLIR_CAPI_EXPORTED intptr_t hwStructTypeGetNumFields(MlirType structType);
142 
143 MLIR_CAPI_EXPORTED MlirType hwTypeAliasTypeGet(MlirStringRef scope,
144  MlirStringRef name,
145  MlirType innerType);
146 
147 MLIR_CAPI_EXPORTED MlirType hwTypeAliasTypeGetCanonicalType(MlirType typeAlias);
148 
149 MLIR_CAPI_EXPORTED MlirType hwTypeAliasTypeGetInnerType(MlirType typeAlias);
150 
151 MLIR_CAPI_EXPORTED MlirStringRef hwTypeAliasTypeGetName(MlirType typeAlias);
152 
153 MLIR_CAPI_EXPORTED MlirStringRef hwTypeAliasTypeGetScope(MlirType typeAlias);
154 
155 //===----------------------------------------------------------------------===//
156 // Attribute API.
157 //===----------------------------------------------------------------------===//
158 
159 MLIR_CAPI_EXPORTED bool hwAttrIsAInnerSymAttr(MlirAttribute);
160 MLIR_CAPI_EXPORTED MlirAttribute hwInnerSymAttrGet(MlirAttribute symName);
161 MLIR_CAPI_EXPORTED MlirAttribute hwInnerSymAttrGetSymName(MlirAttribute);
162 
163 MLIR_CAPI_EXPORTED bool hwAttrIsAInnerRefAttr(MlirAttribute);
164 MLIR_CAPI_EXPORTED MlirAttribute hwInnerRefAttrGet(MlirAttribute moduleName,
165  MlirAttribute innerSym);
166 MLIR_CAPI_EXPORTED MlirAttribute hwInnerRefAttrGetName(MlirAttribute);
167 MLIR_CAPI_EXPORTED MlirAttribute hwInnerRefAttrGetModule(MlirAttribute);
168 
169 MLIR_CAPI_EXPORTED bool hwAttrIsAParamDeclAttr(MlirAttribute);
170 MLIR_CAPI_EXPORTED MlirAttribute hwParamDeclAttrGet(MlirStringRef name,
171  MlirType type,
172  MlirAttribute value);
173 MLIR_CAPI_EXPORTED MlirStringRef hwParamDeclAttrGetName(MlirAttribute decl);
174 MLIR_CAPI_EXPORTED MlirType hwParamDeclAttrGetType(MlirAttribute decl);
175 MLIR_CAPI_EXPORTED MlirAttribute hwParamDeclAttrGetValue(MlirAttribute decl);
176 
177 MLIR_CAPI_EXPORTED bool hwAttrIsAParamDeclRefAttr(MlirAttribute);
178 MLIR_CAPI_EXPORTED MlirAttribute hwParamDeclRefAttrGet(MlirContext ctx,
179  MlirStringRef cName);
180 MLIR_CAPI_EXPORTED MlirStringRef hwParamDeclRefAttrGetName(MlirAttribute decl);
181 MLIR_CAPI_EXPORTED MlirType hwParamDeclRefAttrGetType(MlirAttribute decl);
182 
183 MLIR_CAPI_EXPORTED bool hwAttrIsAParamVerbatimAttr(MlirAttribute);
184 MLIR_CAPI_EXPORTED MlirAttribute hwParamVerbatimAttrGet(MlirAttribute text);
185 
186 MLIR_CAPI_EXPORTED bool hwAttrIsAOutputFileAttr(MlirAttribute);
187 MLIR_CAPI_EXPORTED MlirAttribute hwOutputFileGetFromFileName(
188  MlirAttribute text, bool excludeFromFileList, bool includeReplicatedOp);
189 
190 #ifdef __cplusplus
191 }
192 #endif
193 
194 #endif // CIRCT_C_DIALECT_HW_H
lowerAnnotationsNoRefTypePorts FirtoolPreserveValuesMode value
Definition: Firtool.cpp:95
MlirType uint64_t numElements
Definition: CHIRRTL.cpp:26
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:133
MLIR_CAPI_EXPORTED intptr_t hwModuleTypeGetNumOutputs(MlirType type)
Get an HW module type's number of outputs.
Definition: HW.cpp:117
MLIR_CAPI_EXPORTED MlirType hwParamDeclAttrGetType(MlirAttribute decl)
Definition: HW.cpp:257
MLIR_CAPI_EXPORTED MlirAttribute hwOutputFileGetFromFileName(MlirAttribute text, bool excludeFromFileList, bool includeReplicatedOp)
Definition: HW.cpp:296
MLIR_CAPI_EXPORTED MlirAttribute hwInnerRefAttrGet(MlirAttribute moduleName, MlirAttribute innerSym)
Definition: HW.cpp:228
MLIR_CAPI_EXPORTED bool hwTypeIsAArrayType(MlirType)
If the type is an HW array.
Definition: HW.cpp:39
MLIR_CAPI_EXPORTED MlirAttribute hwParamIntTypeGetWidthAttr(MlirType)
Definition: HW.cpp:59
MLIR_CAPI_EXPORTED MlirAttribute hwInnerRefAttrGetModule(MlirAttribute)
Definition: HW.cpp:239
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:109
MLIR_CAPI_EXPORTED int64_t hwGetBitWidth(MlirType)
Return the hardware bit width of a type.
Definition: HW.cpp:35
MLIR_CAPI_EXPORTED MlirType hwTypeAliasTypeGet(MlirStringRef scope, MlirStringRef name, MlirType innerType)
Definition: HW.cpp:175
MLIR_CAPI_EXPORTED MlirType hwModuleTypeGet(MlirContext ctx, intptr_t numPorts, HWModulePort const *ports)
Creates an HW module type.
Definition: HW.cpp:77
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:37
MLIR_CAPI_EXPORTED MlirAttribute hwInnerSymAttrGetSymName(MlirAttribute)
Definition: HW.cpp:219
MLIR_CAPI_EXPORTED MlirAttribute hwStructTypeGetFieldIndex(MlirType structType, MlirStringRef fieldName)
Definition: HW.cpp:149
MLIR_CAPI_EXPORTED HWStructFieldInfo hwStructTypeGetFieldNum(MlirType structType, unsigned idx)
Definition: HW.cpp:162
HWModulePortDirection
Definition: HW.h:32
@ Input
Definition: HW.h:32
@ Output
Definition: HW.h:32
@ InOut
Definition: HW.h:32
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:41
MLIR_CAPI_EXPORTED MlirType hwParamIntTypeGet(MlirAttribute parameter)
Definition: HW.cpp:55
MLIR_CAPI_EXPORTED MlirAttribute hwParamDeclAttrGetValue(MlirAttribute decl)
Definition: HW.cpp:260
MLIR_CAPI_EXPORTED bool hwTypeIsATypeAliasType(MlirType)
If the type is an HW type alias.
Definition: HW.cpp:171
MLIR_CAPI_EXPORTED MlirType hwTypeAliasTypeGetCanonicalType(MlirType typeAlias)
Definition: HW.cpp:187
MLIR_CAPI_EXPORTED MlirStringRef hwTypeAliasTypeGetName(MlirType typeAlias)
Definition: HW.cpp:197
MLIR_CAPI_EXPORTED intptr_t hwModuleTypeGetNumInputs(MlirType type)
Get an HW module type's number of inputs.
Definition: HW.cpp:105
MLIR_CAPI_EXPORTED bool hwTypeIsAIntType(MlirType)
If the type is an HW int.
Definition: HW.cpp:53
MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(HW, hw)
MLIR_CAPI_EXPORTED MlirAttribute hwInnerRefAttrGetName(MlirAttribute)
Definition: HW.cpp:235
MLIR_CAPI_EXPORTED bool hwAttrIsAInnerRefAttr(MlirAttribute)
Definition: HW.cpp:224
MLIR_CAPI_EXPORTED MlirAttribute hwInnerSymAttrGet(MlirAttribute symName)
Definition: HW.cpp:215
MLIR_CAPI_EXPORTED MlirType hwStructTypeGetField(MlirType structType, MlirStringRef fieldName)
Definition: HW.cpp:144
MLIR_CAPI_EXPORTED MlirType hwTypeAliasTypeGetInnerType(MlirType typeAlias)
Definition: HW.cpp:192
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:113
MLIR_CAPI_EXPORTED bool hwAttrIsAParamDeclRefAttr(MlirAttribute)
Definition: HW.cpp:264
MLIR_CAPI_EXPORTED bool hwAttrIsAOutputFileAttr(MlirAttribute)
Definition: HW.cpp:292
MLIR_CAPI_EXPORTED MlirAttribute hwParamDeclAttrGet(MlirStringRef name, MlirType type, MlirAttribute value)
Definition: HW.cpp:246
MLIR_CAPI_EXPORTED MlirStringRef hwTypeAliasTypeGetScope(MlirType typeAlias)
Definition: HW.cpp:202
MLIR_CAPI_EXPORTED bool hwTypeIsAStructType(MlirType)
If the type is an HW struct.
Definition: HW.cpp:129
MLIR_CAPI_EXPORTED bool hwAttrIsAInnerSymAttr(MlirAttribute)
Definition: HW.cpp:211
MLIR_CAPI_EXPORTED bool hwTypeIsAInOut(MlirType type)
If the type is an HW inout.
Definition: HW.cpp:71
MLIR_CAPI_EXPORTED MlirType hwInOutTypeGetElementType(MlirType)
Returns the element type of an inout type.
Definition: HW.cpp:67
MLIR_CAPI_EXPORTED MlirStringRef hwParamDeclRefAttrGetName(MlirAttribute decl)
Definition: HW.cpp:275
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:125
MLIR_CAPI_EXPORTED MlirType hwInOutTypeGet(MlirType element)
Creates an HW inout type in the context associated with element.
Definition: HW.cpp:63
MLIR_CAPI_EXPORTED MlirType hwArrayTypeGetElementType(MlirType)
returns the element type of an array type
Definition: HW.cpp:45
MLIR_CAPI_EXPORTED bool hwAttrIsAParamVerbatimAttr(MlirAttribute)
Definition: HW.cpp:282
MLIR_CAPI_EXPORTED bool hwAttrIsAParamDeclAttr(MlirAttribute)
Definition: HW.cpp:243
MLIR_CAPI_EXPORTED bool hwTypeIsAModuleType(MlirType type)
If the type is an HW module type.
Definition: HW.cpp:73
MLIR_CAPI_EXPORTED MlirAttribute hwParamDeclRefAttrGet(MlirContext ctx, MlirStringRef cName)
Definition: HW.cpp:268
MLIR_CAPI_EXPORTED intptr_t hwStructTypeGetNumFields(MlirType structType)
Definition: HW.cpp:157
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:121
MLIR_CAPI_EXPORTED intptr_t hwArrayTypeGetSize(MlirType)
returns the size of an array type
Definition: HW.cpp:49
MLIR_CAPI_EXPORTED MlirStringRef hwParamDeclAttrGetName(MlirAttribute decl)
Definition: HW.cpp:254
MLIR_CAPI_EXPORTED MlirAttribute hwParamVerbatimAttrGet(MlirAttribute text)
Definition: HW.cpp:285
MLIR_CAPI_EXPORTED MlirType hwParamDeclRefAttrGetType(MlirAttribute decl)
Definition: HW.cpp:278
mlir::Type innerType(mlir::Type type)
Definition: ESITypes.cpp:184
Definition: hw.py:1
HWModulePortDirection dir
Definition: HW.h:38
MlirAttribute name
Definition: HW.h:36
MlirType type
Definition: HW.h:37
MlirIdentifier name
Definition: HW.h:27
MlirType type
Definition: HW.h:28