18 #include "mlir/CAPI/IR.h"
19 #include "mlir/CAPI/Registration.h"
20 #include "mlir/CAPI/Support.h"
22 using namespace circt;
46 return wrap(
unwrap(type).cast<ArrayType>().getElementType());
50 return unwrap(type).cast<ArrayType>().getNumElements();
68 return wrap(
unwrap(type).cast<InOutType>().getElementType());
74 return isa<ModuleType>(
unwrap(type));
79 SmallVector<ModulePort> modulePorts;
80 for (intptr_t i = 0; i < numPorts; ++i) {
96 StringAttr name = cast<StringAttr>(
unwrap(port.
name));
99 modulePorts.push_back(
ModulePort{name, type, dir});
106 return cast<ModuleType>(
unwrap(type)).getNumInputs();
110 return wrap(cast<ModuleType>(
unwrap(type)).getInputType(index));
114 return wrap(cast<ModuleType>(
unwrap(type)).getInputName(index));
118 return cast<ModuleType>(
unwrap(type)).getNumOutputs();
122 return wrap(cast<ModuleType>(
unwrap(type)).getOutputType(index));
126 return wrap(cast<ModuleType>(
unwrap(type)).getOutputName(index));
130 return unwrap(type).isa<StructType>();
135 SmallVector<StructType::FieldInfo> fieldInfos;
138 fieldInfos.push_back(StructType::FieldInfo{
139 unwrap(elements[i].name).cast<StringAttr>(),
unwrap(elements[i].type)});
145 StructType st =
unwrap(structType).cast<StructType>();
146 return wrap(st.getFieldType(
unwrap(fieldName)));
150 MlirStringRef fieldName) {
151 StructType st =
unwrap(structType).cast<StructType>();
152 if (
auto idx = st.getFieldIndex(
unwrap(fieldName)))
158 StructType st =
unwrap(structType).cast<StructType>();
159 return st.getElements().size();
163 StructType st =
unwrap(structType).cast<StructType>();
164 auto cppField = st.getElements()[idx];
172 return unwrap(type).isa<TypeAliasType>();
176 MlirType cInnerType) {
177 StringRef scope =
unwrap(cScope);
178 StringRef name =
unwrap(cName);
180 FlatSymbolRefAttr nameRef =
188 TypeAliasType type =
unwrap(typeAlias).cast<TypeAliasType>();
189 return wrap(type.getCanonicalType());
193 TypeAliasType type =
unwrap(typeAlias).cast<TypeAliasType>();
194 return wrap(type.getInnerType());
198 TypeAliasType type =
unwrap(typeAlias).cast<TypeAliasType>();
199 return wrap(type.getRef().getLeafReference().getValue());
203 TypeAliasType type =
unwrap(typeAlias).cast<TypeAliasType>();
204 return wrap(type.getRef().getRootReference().getValue());
212 return unwrap(attr).isa<InnerSymAttr>();
221 (Attribute)
unwrap(innerSymAttr).cast<InnerSymAttr>().getSymName());
225 return unwrap(attr).isa<InnerRefAttr>();
229 MlirAttribute innerSym) {
230 auto moduleNameAttr =
unwrap(moduleName).cast<StringAttr>();
231 auto innerSymAttr =
unwrap(innerSym).cast<StringAttr>();
240 return wrap((Attribute)
unwrap(innerRefAttr).cast<InnerRefAttr>().getModule());
244 return unwrap(attr).isa<ParamDeclAttr>();
248 MlirAttribute cValue) {
249 auto type =
unwrap(cType);
258 return wrap(
unwrap(decl).cast<ParamDeclAttr>().getType());
261 return wrap(
unwrap(decl).cast<ParamDeclAttr>().getValue());
265 return unwrap(attr).isa<ParamDeclRefAttr>();
269 MlirStringRef cName) {
279 return wrap(
unwrap(decl).cast<ParamDeclRefAttr>().getType());
283 return unwrap(attr).isa<ParamVerbatimAttr>();
286 auto textAttr =
unwrap(text).cast<StringAttr>();
287 MLIRContext *ctx = textAttr.getContext();
293 return unwrap(attr).isa<OutputFileAttr>();
295 MLIR_CAPI_EXPORTED MlirAttribute
297 bool includeReplicatedOp) {
298 auto fileNameStrAttr =
unwrap(fileName).cast<StringAttr>();
299 return wrap(OutputFileAttr::getFromFilename(
300 fileNameStrAttr.getContext(), fileNameStrAttr.getValue(),
301 excludeFromFileList, includeReplicatedOp));
return wrap(CMemoryType::get(unwrap(ctx), baseType, numElements))
MlirType uint64_t numElements
MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(CHIRRTL, chirrtl, circt::chirrtl::CHIRRTLDialect) MlirType chirrtlTypeGetCMemory(MlirContext ctx
MLIR_CAPI_EXPORTED MlirAttribute hwParamDeclAttrGet(MlirStringRef cName, MlirType cType, MlirAttribute cValue)
MlirAttribute hwInnerRefAttrGetModule(MlirAttribute innerRefAttr)
MLIR_CAPI_EXPORTED MlirType hwParamDeclAttrGetType(MlirAttribute decl)
MlirType hwInOutTypeGet(MlirType element)
Creates an HW inout type in the context associated with element.
MlirType hwArrayTypeGet(MlirType element, size_t size)
Creates a fixed-size HW array type in the context associated with element.
intptr_t hwArrayTypeGetSize(MlirType type)
returns the size of an array type
MlirType hwStructTypeGet(MlirContext ctx, intptr_t numElements, HWStructFieldInfo const *elements)
Creates an HW struct type in the context associated with the elements.
MlirType hwArrayTypeGetElementType(MlirType type)
returns the element type of an array type
intptr_t hwModuleTypeGetNumInputs(MlirType type)
Get an HW module type's number of inputs.
intptr_t hwStructTypeGetNumFields(MlirType structType)
bool hwTypeIsAArrayType(MlirType type)
If the type is an HW array.
bool hwTypeIsATypeAliasType(MlirType type)
If the type is an HW type alias.
MlirType hwTypeAliasTypeGetInnerType(MlirType typeAlias)
MlirType hwTypeAliasTypeGetCanonicalType(MlirType typeAlias)
MlirType hwStructTypeGetField(MlirType structType, MlirStringRef fieldName)
MlirAttribute hwInnerRefAttrGet(MlirAttribute moduleName, MlirAttribute innerSym)
bool hwTypeIsAIntType(MlirType type)
If the type is an HW int.
MlirType hwModuleTypeGetInputType(MlirType type, intptr_t index)
Get an HW module type's input type at a specific index.
bool hwTypeIsAInOut(MlirType type)
If the type is an HW inout.
MlirStringRef hwModuleTypeGetInputName(MlirType type, intptr_t index)
Get an HW module type's input name at a specific index.
MlirType hwModuleTypeGet(MlirContext ctx, intptr_t numPorts, HWModulePort const *ports)
Creates an HW module type.
MlirAttribute hwStructTypeGetFieldIndex(MlirType structType, MlirStringRef fieldName)
MLIR_CAPI_EXPORTED MlirAttribute hwParamDeclAttrGetValue(MlirAttribute decl)
MlirAttribute hwInnerSymAttrGetSymName(MlirAttribute innerSymAttr)
MlirAttribute hwInnerSymAttrGet(MlirAttribute symName)
MlirStringRef hwTypeAliasTypeGetScope(MlirType typeAlias)
MlirType hwInOutTypeGetElementType(MlirType type)
Returns the element type of an inout type.
MlirType hwTypeAliasTypeGet(MlirStringRef cScope, MlirStringRef cName, MlirType cInnerType)
bool hwTypeIsAValueType(MlirType type)
Return true if the specified type can be used as an HW value type, that is the set of types that can ...
bool hwAttrIsAInnerSymAttr(MlirAttribute attr)
MLIR_CAPI_EXPORTED bool hwAttrIsAParamVerbatimAttr(MlirAttribute attr)
bool hwTypeIsAStructType(MlirType type)
If the type is an HW struct.
MLIR_CAPI_EXPORTED bool hwAttrIsAOutputFileAttr(MlirAttribute attr)
MlirType hwParamIntTypeGet(MlirAttribute parameter)
MlirStringRef hwModuleTypeGetOutputName(MlirType type, intptr_t index)
Get an HW module type's output name at a specific index.
MLIR_CAPI_EXPORTED MlirAttribute hwOutputFileGetFromFileName(MlirAttribute fileName, bool excludeFromFileList, bool includeReplicatedOp)
MlirAttribute hwInnerRefAttrGetName(MlirAttribute innerRefAttr)
HWStructFieldInfo hwStructTypeGetFieldNum(MlirType structType, unsigned idx)
bool hwTypeIsAModuleType(MlirType type)
If the type is an HW module type.
MLIR_CAPI_EXPORTED bool hwAttrIsAParamDeclRefAttr(MlirAttribute attr)
int64_t hwGetBitWidth(MlirType type)
Return the hardware bit width of a type.
MLIR_CAPI_EXPORTED MlirStringRef hwParamDeclRefAttrGetName(MlirAttribute decl)
MlirStringRef hwTypeAliasTypeGetName(MlirType typeAlias)
bool hwAttrIsAInnerRefAttr(MlirAttribute attr)
MLIR_CAPI_EXPORTED MlirAttribute hwParamDeclRefAttrGet(MlirContext ctx, MlirStringRef cName)
MLIR_CAPI_EXPORTED bool hwAttrIsAParamDeclAttr(MlirAttribute attr)
MlirType hwModuleTypeGetOutputType(MlirType type, intptr_t index)
Get an HW module type's output type at a specific index.
MlirAttribute hwParamIntTypeGetWidthAttr(MlirType type)
intptr_t hwModuleTypeGetNumOutputs(MlirType type)
Get an HW module type's number of outputs.
MLIR_CAPI_EXPORTED MlirStringRef hwParamDeclAttrGetName(MlirAttribute decl)
MLIR_CAPI_EXPORTED MlirAttribute hwParamVerbatimAttrGet(MlirAttribute text)
MLIR_CAPI_EXPORTED MlirType hwParamDeclRefAttrGetType(MlirAttribute decl)
static EvaluatorValuePtr unwrap(OMEvaluatorValue c)
Direction get(bool isOutput)
Returns an output direction if isOutput is true, otherwise returns an input direction.
uint64_t getWidth(Type t)
mlir::Type innerType(mlir::Type type)
StringAttr getName(ArrayAttr names, size_t idx)
Return the name at the specified index of the ArrayAttr or null if it cannot be determined.
bool isHWValueType(mlir::Type type)
Return true if the specified type can be used as an HW value type, that is the set of types that can ...
int64_t getBitWidth(mlir::Type type)
Return the hardware bit width of a type.
circt::hw::InOutType InOutType
This file defines an intermediate representation for circuits acting as an abstraction for constraint...
HWModulePortDirection dir