CIRCT  18.0.0git
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 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 //===----------------------------------------------------------------------===//
20 #include "mlir-c/IR.h"
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
27  MlirIdentifier name;
28  MlirType type;
29 };
35 struct HWModulePort {
36  MlirAttribute name;
37  MlirType type;
39 };
40 typedef struct HWModulePort HWModulePort;
42 //===----------------------------------------------------------------------===//
43 // Dialect API.
44 //===----------------------------------------------------------------------===//
48 //===----------------------------------------------------------------------===//
49 // Type API.
50 //===----------------------------------------------------------------------===//
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);
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);
65 /// If the type is an HW array
66 MLIR_CAPI_EXPORTED bool hwTypeIsAArrayType(MlirType);
68 /// If the type is an HW inout.
69 MLIR_CAPI_EXPORTED bool hwTypeIsAInOut(MlirType type);
71 /// If the type is an HW module type.
72 MLIR_CAPI_EXPORTED bool hwTypeIsAModuleType(MlirType type);
74 /// If the type is an HW struct.
75 MLIR_CAPI_EXPORTED bool hwTypeIsAStructType(MlirType);
77 /// If the type is an HW type alias.
78 MLIR_CAPI_EXPORTED bool hwTypeIsATypeAliasType(MlirType);
80 /// If the type is an HW int.
81 MLIR_CAPI_EXPORTED bool hwTypeIsAIntType(MlirType);
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);
86 /// returns the element type of an array type
87 MLIR_CAPI_EXPORTED MlirType hwArrayTypeGetElementType(MlirType);
89 /// returns the size of an array type
90 MLIR_CAPI_EXPORTED intptr_t hwArrayTypeGetSize(MlirType);
92 /// Creates an HW inout type in the context associated with element.
93 MLIR_CAPI_EXPORTED MlirType hwInOutTypeGet(MlirType element);
95 /// Returns the element type of an inout type.
96 MLIR_CAPI_EXPORTED MlirType hwInOutTypeGetElementType(MlirType);
98 /// Creates an HW module type.
99 MLIR_CAPI_EXPORTED MlirType hwModuleTypeGet(MlirContext ctx, intptr_t numPorts,
100  HWModulePort const *ports);
102 /// Get an HW module type's number of inputs.
103 MLIR_CAPI_EXPORTED intptr_t hwModuleTypeGetNumInputs(MlirType type);
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);
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);
113 /// Get an HW module type's number of outputs.
114 MLIR_CAPI_EXPORTED intptr_t hwModuleTypeGetNumOutputs(MlirType type);
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);
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);
128 MLIR_CAPI_EXPORTED MlirType hwStructTypeGetField(MlirType structType,
129  MlirStringRef fieldName);
131 MLIR_CAPI_EXPORTED MlirType hwParamIntTypeGet(MlirAttribute parameter);
133 MLIR_CAPI_EXPORTED MlirAttribute hwParamIntTypeGetWidthAttr(MlirType);
135 MLIR_CAPI_EXPORTED MlirAttribute
136 hwStructTypeGetFieldIndex(MlirType structType, MlirStringRef fieldName);
139 hwStructTypeGetFieldNum(MlirType structType, unsigned idx);
141 MLIR_CAPI_EXPORTED intptr_t hwStructTypeGetNumFields(MlirType structType);
143 MLIR_CAPI_EXPORTED MlirType hwTypeAliasTypeGet(MlirStringRef scope,
144  MlirStringRef name,
145  MlirType innerType);
147 MLIR_CAPI_EXPORTED MlirType hwTypeAliasTypeGetCanonicalType(MlirType typeAlias);
149 MLIR_CAPI_EXPORTED MlirType hwTypeAliasTypeGetInnerType(MlirType typeAlias);
151 MLIR_CAPI_EXPORTED MlirStringRef hwTypeAliasTypeGetName(MlirType typeAlias);
153 MLIR_CAPI_EXPORTED MlirStringRef hwTypeAliasTypeGetScope(MlirType typeAlias);
155 //===----------------------------------------------------------------------===//
156 // Attribute API.
157 //===----------------------------------------------------------------------===//
159 MLIR_CAPI_EXPORTED bool hwAttrIsAInnerSymAttr(MlirAttribute);
160 MLIR_CAPI_EXPORTED MlirAttribute hwInnerSymAttrGet(MlirAttribute symName);
161 MLIR_CAPI_EXPORTED MlirAttribute hwInnerSymAttrGetSymName(MlirAttribute);
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);
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);
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);
183 MLIR_CAPI_EXPORTED bool hwAttrIsAParamVerbatimAttr(MlirAttribute);
184 MLIR_CAPI_EXPORTED MlirAttribute hwParamVerbatimAttrGet(MlirAttribute text);
186 MLIR_CAPI_EXPORTED bool hwAttrIsAOutputFileAttr(MlirAttribute);
187 MLIR_CAPI_EXPORTED MlirAttribute hwOutputFileGetFromFileName(
188  MlirAttribute text, bool excludeFromFileList, bool includeReplicatedOp);
190 #ifdef __cplusplus
191 }
192 #endif
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
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_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
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