16#include "mlir/CAPI/IR.h"
17#include "mlir/CAPI/Registration.h"
18#include "mlir/CAPI/Support.h"
19#include "llvm/ADT/PostOrderIterator.h"
49 return wrap(ArrayType::get(
unwrap(element), size));
53 return wrap(cast<ArrayType>(
unwrap(type)).getElementType());
57 return cast<ArrayType>(
unwrap(type)).getNumElements();
63 return wrap(IntType::get(cast<TypedAttr>(
unwrap(parameter))));
67 return wrap(cast<IntType>(
unwrap(type)).getWidth());
75 return wrap(cast<InOutType>(
unwrap(type)).getElementType());
81 return isa<ModuleType>(
unwrap(type));
86 SmallVector<ModulePort> modulePorts;
87 for (intptr_t i = 0; i < numPorts; ++i) {
92 case HWModulePortDirection::Input:
95 case HWModulePortDirection::Output:
100 StringAttr name = cast<StringAttr>(
unwrap(port.
name));
103 modulePorts.push_back(
ModulePort{name, type, dir});
106 return wrap(ModuleType::get(
unwrap(ctx), modulePorts));
110 return cast<ModuleType>(
unwrap(type)).getNumInputs();
114 return wrap(cast<ModuleType>(
unwrap(type)).getInputType(index));
118 return wrap(cast<ModuleType>(
unwrap(type)).getInputName(index));
122 return cast<ModuleType>(
unwrap(type)).getNumOutputs();
126 return wrap(cast<ModuleType>(
unwrap(type)).getOutputType(index));
130 return wrap(cast<ModuleType>(
unwrap(type)).getOutputName(index));
134 auto port = cast<ModuleType>(
unwrap(type)).getPorts()[index];
139 dir = HWModulePortDirection::Input;
142 dir = HWModulePortDirection::Output;
146 ret->
name =
wrap(
static_cast<Attribute
>(port.name));
152 return isa<StructType>(
unwrap(type));
157 SmallVector<StructType::FieldInfo> fieldInfos;
160 fieldInfos.push_back(StructType::FieldInfo{
161 cast<StringAttr>(
unwrap(elements[i].name)),
unwrap(elements[i].type)});
163 return wrap(StructType::get(
unwrap(ctx), fieldInfos));
167 StructType st = cast<StructType>(
unwrap(structType));
168 return wrap(st.getFieldType(
unwrap(fieldName)));
172 MlirStringRef fieldName) {
173 StructType st = cast<StructType>(
unwrap(structType));
174 if (
auto idx = st.getFieldIndex(
unwrap(fieldName)))
175 return wrap(IntegerAttr::get(IntegerType::get(st.getContext(), 32), *idx));
176 return wrap(UnitAttr::get(st.getContext()));
180 StructType st = cast<StructType>(
unwrap(structType));
181 return st.getElements().size();
185 StructType st = cast<StructType>(
unwrap(structType));
186 auto cppField = st.getElements()[idx];
197 SmallVector<UnionType::FieldInfo> fieldInfos;
200 fieldInfos.push_back(
201 UnionType::FieldInfo{cast<StringAttr>(
unwrap(elements[i].name)),
204 return wrap(UnionType::get(
unwrap(ctx), fieldInfos));
208 UnionType ut = cast<UnionType>(
unwrap(unionType));
209 return wrap(ut.getFieldType(
unwrap(fieldName)));
213 MlirStringRef fieldName) {
214 UnionType ut = cast<UnionType>(
unwrap(unionType));
215 if (
auto idx = ut.getFieldIndex(
unwrap(fieldName)))
216 return wrap(IntegerAttr::get(IntegerType::get(ut.getContext(), 32), *idx));
217 return wrap(UnitAttr::get(ut.getContext()));
221 UnionType ut = cast<UnionType>(
unwrap(unionType));
222 return ut.getElements().size();
226 UnionType ut = cast<UnionType>(
unwrap(unionType));
227 auto cppField = ut.getElements()[idx];
231 ret.
offset = cppField.offset;
236 return isa<TypeAliasType>(
unwrap(type));
240 MlirType cInnerType) {
241 StringRef scope =
unwrap(cScope);
242 StringRef name =
unwrap(cName);
243 Type innerType =
unwrap(cInnerType);
244 FlatSymbolRefAttr nameRef =
245 FlatSymbolRefAttr::get(innerType.getContext(), name);
247 SymbolRefAttr::get(innerType.getContext(), scope, {nameRef});
248 return wrap(TypeAliasType::get(ref, innerType));
252 TypeAliasType type = cast<TypeAliasType>(
unwrap(typeAlias));
253 return wrap(type.getCanonicalType());
257 TypeAliasType type = cast<TypeAliasType>(
unwrap(typeAlias));
258 return wrap(type.getInnerType());
262 TypeAliasType type = cast<TypeAliasType>(
unwrap(typeAlias));
263 return wrap(type.getRef().getLeafReference().getValue());
267 TypeAliasType type = cast<TypeAliasType>(
unwrap(typeAlias));
268 return wrap(type.getRef().getRootReference().getValue());
276 return isa<InnerSymAttr>(
unwrap(attr));
280 return wrap(InnerSymAttr::get(cast<StringAttr>(
unwrap(symName))));
288 return wrap((Attribute)cast<InnerSymAttr>(
unwrap(innerSymAttr)).getSymName());
292 return isa<InnerRefAttr>(
unwrap(attr));
296 MlirAttribute innerSym) {
297 auto moduleNameAttr = cast<StringAttr>(
unwrap(moduleName));
298 auto innerSymAttr = cast<StringAttr>(
unwrap(innerSym));
299 return wrap(InnerRefAttr::get(moduleNameAttr, innerSymAttr));
303 return wrap((Attribute)cast<InnerRefAttr>(
unwrap(innerRefAttr)).getName());
307 return wrap((Attribute)cast<InnerRefAttr>(
unwrap(innerRefAttr)).getModule());
311 return isa<ParamDeclAttr>(
unwrap(attr));
315 MlirAttribute cValue) {
316 auto type =
unwrap(cType);
317 auto name = StringAttr::get(type.getContext(),
unwrap(cName));
319 ParamDeclAttr::get(type.getContext(), name, type,
unwrap(cValue)));
322 return wrap(cast<ParamDeclAttr>(
unwrap(decl)).getName().getValue());
325 return wrap(cast<ParamDeclAttr>(
unwrap(decl)).getType());
328 return wrap(cast<ParamDeclAttr>(
unwrap(decl)).getValue());
332 return isa<ParamDeclRefAttr>(
unwrap(attr));
336 MlirStringRef cName) {
337 auto name = StringAttr::get(
unwrap(ctx),
unwrap(cName));
338 return wrap(ParamDeclRefAttr::get(
unwrap(ctx), name,
339 IntegerType::get(
unwrap(ctx), 32)));
343 return wrap(cast<ParamDeclRefAttr>(
unwrap(decl)).getName().getValue());
346 return wrap(cast<ParamDeclRefAttr>(
unwrap(decl)).getType());
350 return isa<ParamVerbatimAttr>(
unwrap(attr));
353 auto textAttr = cast<StringAttr>(
unwrap(text));
354 MLIRContext *ctx = textAttr.getContext();
355 auto type = NoneType::get(ctx);
356 return wrap(ParamVerbatimAttr::get(ctx, textAttr, type));
360 return isa<OutputFileAttr>(
unwrap(attr));
362MLIR_CAPI_EXPORTED MlirAttribute
364 bool includeReplicatedOp) {
365 auto fileNameStrAttr = cast<StringAttr>(
unwrap(fileName));
366 return wrap(OutputFileAttr::getFromFilename(
367 fileNameStrAttr.getContext(), fileNameStrAttr.getValue(),
368 excludeFromFileList, includeReplicatedOp));
372 auto outputFileAttr = cast<OutputFileAttr>(
unwrap(outputFile));
373 return wrap(outputFileAttr.getFilename().getValue());
381 delete unwrap(instanceGraph);
384MLIR_CAPI_EXPORTED HWInstanceGraphNode
386 return wrap(
unwrap(instanceGraph)->getTopLevelNode());
389MLIR_CAPI_EXPORTED
void
394 for (
const auto &inst : llvm::post_order(graph)) {
395 callback(
wrap(inst), userData);
400 HWInstanceGraphNode rhs) {
404MLIR_CAPI_EXPORTED MlirModule
406 return wrap(dyn_cast<ModuleOp>(
unwrap(node)->getModule().getOperation()));
409MLIR_CAPI_EXPORTED MlirOperation
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
static void registerPasses()
MLIR_CAPI_EXPORTED MlirAttribute hwParamDeclAttrGet(MlirStringRef cName, MlirType cType, MlirAttribute cValue)
MlirAttribute hwInnerRefAttrGetModule(MlirAttribute innerRefAttr)
MLIR_CAPI_EXPORTED MlirType hwParamDeclAttrGetType(MlirAttribute decl)
MlirType hwUnionTypeGet(MlirContext ctx, intptr_t numElements, HWUnionFieldInfo const *elements)
Creates an HW union type in the context associated with the elements.
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
MLIR_CAPI_EXPORTED HWInstanceGraphNode hwInstanceGraphGetTopLevelNode(HWInstanceGraph instanceGraph)
intptr_t hwModuleTypeGetNumInputs(MlirType type)
Get an HW module type's number of inputs.
MLIR_CAPI_EXPORTED MlirOperation hwInstanceGraphNodeGetModuleOp(HWInstanceGraphNode node)
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)
MlirStringRef hwOutputFileGetFileName(MlirAttribute outputFile)
MlirType hwTypeAliasTypeGetCanonicalType(MlirType typeAlias)
MlirType hwStructTypeGetField(MlirType structType, MlirStringRef fieldName)
MlirAttribute hwInnerRefAttrGet(MlirAttribute moduleName, MlirAttribute innerSym)
MLIR_CAPI_EXPORTED bool hwInstanceGraphNodeEqual(HWInstanceGraphNode lhs, HWInstanceGraphNode rhs)
MLIR_CAPI_EXPORTED MlirModule hwInstanceGraphNodeGetModule(HWInstanceGraphNode node)
MLIR_CAPI_EXPORTED HWInstanceGraph hwInstanceGraphGet(MlirOperation operation)
MlirType hwGetCanonicalType(MlirType type)
Recursively remove HW type aliases from a type and its subelements.
bool hwTypeIsAIntType(MlirType type)
If the type is an HW int.
void hwModuleTypeGetPort(MlirType type, intptr_t index, HWModulePort *ret)
Get an HW module type's port info at a specific index.
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)
intptr_t hwUnionTypeGetNumFields(MlirType unionType)
MLIR_CAPI_EXPORTED void hwInstanceGraphDestroy(HWInstanceGraph instanceGraph)
MLIR_CAPI_EXPORTED void hwInstanceGraphForEachNode(HWInstanceGraph instanceGraph, HWInstanceGraphNodeCallback callback, void *userData)
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)
MlirType hwUnionTypeGetField(MlirType unionType, MlirStringRef fieldName)
MlirAttribute hwInnerSymAttrGetEmpty(MlirContext ctx)
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)
HWUnionFieldInfo hwUnionTypeGetFieldNum(MlirType unionType, unsigned idx)
int64_t hwGetBitWidth(MlirType type)
Return the hardware bit width of a type.
MLIR_CAPI_EXPORTED MlirStringRef hwParamDeclRefAttrGetName(MlirAttribute decl)
MlirStringRef hwTypeAliasTypeGetName(MlirType typeAlias)
MlirAttribute hwUnionTypeGetFieldIndex(MlirType unionType, MlirStringRef fieldName)
bool hwAttrIsAInnerRefAttr(MlirAttribute attr)
MLIR_CAPI_EXPORTED MlirAttribute hwParamDeclRefAttrGet(MlirContext ctx, MlirStringRef cName)
MLIR_CAPI_EXPORTED bool hwAttrIsAParamDeclAttr(MlirAttribute attr)
bool hwTypeIsAUnionType(MlirType type)
If the type is an HW union.
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)
MLIR_CAPI_EXPORTED void registerHWPasses(void)
void(* HWInstanceGraphNodeCallback)(HWInstanceGraphNode, void *)
static EvaluatorValuePtr unwrap(OMEvaluatorValue c)
DEFINE_C_API_PTR_METHODS(SynthLongestPathHistory, llvm::ImmutableListImpl< DebugPoint >) llvm
HW-specific instance graph with a virtual entry node linking to all publicly visible modules.
This is a Node in the InstanceGraph.
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.
mlir::Type getCanonicalType(mlir::Type type)
Recursively remove HW type aliases from a type and its subelements.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
HWModulePortDirection dir