13 #include "mlir/CAPI/IR.h"
14 #include "mlir/CAPI/Registration.h"
15 #include "mlir/CAPI/Support.h"
16 #include "mlir/CAPI/Utils.h"
17 #include "mlir/IR/Builders.h"
18 #include "mlir/IR/SymbolTable.h"
19 #include "mlir/Parser/Parser.h"
20 #include "mlir/Support/FileUtilities.h"
22 using namespace circt;
30 return isa<ChannelType>(
unwrap(type));
35 auto signalEnum = symbolizeChannelSignaling(signaling);
38 auto cppInner =
unwrap(inner);
44 return wrap(cast<ChannelType>(
unwrap(channelType)).getInner());
47 return (uint32_t)cast<ChannelType>(
unwrap(channelType)).getSignaling();
50 return cast<ChannelType>(
unwrap(channelType)).getDataDelay();
54 return isa<AnyType>(
unwrap(type));
61 return isa<ListType>(
unwrap(type));
65 auto cppInner =
unwrap(inner);
70 return wrap(cast<ListType>(
unwrap(list)).getElementType());
74 ModuleOp modOp =
unwrap(cMod);
76 mlir::parseSourceFile<ModuleOp>(
unwrap(filename), modOp.getContext());
77 Block *loadedBlock = loadedMod->getBody();
78 assert(!modOp->getRegions().empty());
79 if (modOp.getBodyRegion().empty()) {
80 modOp.getBodyRegion().push_back(loadedBlock);
83 auto &ops = modOp.getBody()->getOperations();
84 ops.splice(ops.end(), loadedBlock->getOperations());
94 unwrap(impl_type), [genFunc, userData](ServiceImplementReqOp req,
95 ServiceDeclOpInterface decl,
96 ServiceImplRecordOp record) {
98 wrap(record.getOperation()), userData));
106 return isa<ChannelBundleType>(
unwrap(type));
112 SmallVector<BundledChannel, 4> channelsVector(llvm::map_range(
113 ArrayRef<CirctESIBundleTypeBundleChannel>(channels, numChannels),
117 cast<ChannelType>(
unwrap(channel.channelType))};
123 return cast<ChannelBundleType>(
unwrap(bundle)).getResettable() != UnitAttr();
126 return cast<ChannelBundleType>(
unwrap(bundle)).getChannels().size();
131 cast<ChannelBundleType>(
unwrap(bundle)).getChannels()[idx];
141 return isa<AppIDAttr>(
unwrap(attr));
157 std::optional<uint64_t> index = cast<AppIDAttr>(
unwrap(attr)).getIndex();
160 *indexOut = index.value();
165 return isa<AppIDPathAttr>(
unwrap(attr));
170 MlirAttribute
const *cElements) {
171 SmallVector<AppIDAttr, 8> elements;
173 elements.push_back(cast<AppIDAttr>(
unwrap(cElements[i])));
178 return wrap(cast<AppIDPathAttr>(
unwrap(attr)).getRoot());
181 return cast<AppIDPathAttr>(
unwrap(attr)).getPath().size();
185 return wrap(cast<AppIDPathAttr>(
unwrap(attr)).getPath()[index]);
204 MLIR_CAPI_EXPORTED MlirAttribute
206 auto mod = cast<hw::HWModuleLike>(
unwrap(op));
207 return wrap(
unwrap(idx)->getChildAppIDsOf(mod));
212 MlirOperation fromMod,
215 auto mod = cast<hw::HWModuleLike>(
unwrap(fromMod));
216 auto path = cast<AppIDAttr>(
unwrap(appid));
217 FailureOr<ArrayAttr> instPath =
219 if (failed(instPath))
220 return MlirAttribute{
nullptr};
221 return wrap(*instPath);
assert(baseType &&"element must be base type")
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
void circtESIRegisterGlobalServiceGenerator(MlirStringRef impl_type, CirctESIServiceGeneratorFunc genFunc, void *userData)
MlirType circtESIAnyTypeGet(MlirContext ctxt)
bool circtESIAppIDAttrGetIndex(MlirAttribute attr, uint64_t *indexOut)
bool circtESITypeIsAnAnyType(MlirType type)
MLIR_CAPI_EXPORTED MlirAttribute circtESIAppIDIndexGetAppIDPath(CirctESIAppIDIndex idx, MlirOperation fromMod, MlirAttribute appid, MlirLocation loc)
bool circtESIBundleTypeGetResettable(MlirType bundle)
void circtESIAppendMlirFile(MlirModule cMod, MlirStringRef filename)
MlirType circtESIChannelGetInner(MlirType channelType)
bool circtESITypeIsABundleType(MlirType type)
uint64_t circtESIAppIDAttrPathGetNumComponents(MlirAttribute attr)
uint64_t circtESIChannelGetDataDelay(MlirType channelType)
MlirOperation circtESILookup(MlirModule mod, MlirStringRef symbol)
MLIR_CAPI_EXPORTED void circtESIAppIDIndexFree(CirctESIAppIDIndex index)
Free an AppIDIndex.
MlirStringRef circtESIAppIDAttrGetName(MlirAttribute attr)
MLIR_CAPI_EXPORTED MlirAttribute circtESIAppIDIndexGetChildAppIDsOf(CirctESIAppIDIndex idx, MlirOperation op)
MlirAttribute circtESIAppIDAttrPathGet(MlirContext ctxt, MlirAttribute root, intptr_t numElements, MlirAttribute const *cElements)
size_t circtESIBundleTypeGetNumChannels(MlirType bundle)
MlirType circtESIListTypeGet(MlirType inner)
bool circtESIAttributeIsAnAppIDAttr(MlirAttribute attr)
uint32_t circtESIChannelGetSignaling(MlirType channelType)
CirctESIBundleTypeBundleChannel circtESIBundleTypeGetChannel(MlirType bundle, size_t idx)
MlirAttribute circtESIAppIDAttrPathGetComponent(MlirAttribute attr, uint64_t index)
MlirAttribute circtESIAppIDAttrPathGetRoot(MlirAttribute attr)
bool circtESITypeIsAListType(MlirType type)
bool circtESIAttributeIsAnAppIDPathAttr(MlirAttribute attr)
MlirType circtESIListTypeGetElementType(MlirType list)
bool circtESITypeIsAChannelType(MlirType type)
MlirType circtESIBundleTypeGet(MlirContext cctxt, size_t numChannels, const CirctESIBundleTypeBundleChannel *channels, bool resettable)
MLIR_CAPI_EXPORTED CirctESIAppIDIndex circtESIAppIDIndexGet(MlirOperation root)
Create an index of appids through which to do appid lookups efficiently.
MlirType circtESIChannelTypeGet(MlirType inner, uint32_t signaling, uint64_t dataDelay)
MlirAttribute circtESIAppIDAttrGet(MlirContext ctxt, MlirStringRef name, uint64_t index)
MlirAttribute circtESIAppIDAttrGetNoIdx(MlirContext ctxt, MlirStringRef name)
MlirLogicalResult(* CirctESIServiceGeneratorFunc)(MlirOperation serviceImplementReqOp, MlirOperation declOp, MlirOperation recordOp, void *userData)
static EvaluatorValuePtr unwrap(OMEvaluatorValue c)
An index for resolving AppIDPaths to dynamic instances.
void registerGenerator(StringRef implType, ServiceGeneratorFunc gen)
Add a generator to this registry.
static ServiceGeneratorDispatcher & globalDispatcher()
Get the global dispatcher.
Direction get(bool isOutput)
Returns an output direction if isOutput is true, otherwise returns an input direction.
StringAttr getName(ArrayAttr names, size_t idx)
Return the name at the specified index of the ArrayAttr or null if it cannot be determined.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
ChannelDirection direction