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));
34 auto signalEnum = symbolizeChannelSignaling(signaling);
37 auto cppInner =
unwrap(inner);
42 return wrap(cast<ChannelType>(
unwrap(channelType)).getInner());
45 return (uint32_t)cast<ChannelType>(
unwrap(channelType)).getSignaling();
49 return isa<AnyType>(
unwrap(type));
56 return isa<ListType>(
unwrap(type));
60 auto cppInner =
unwrap(inner);
65 return wrap(cast<ListType>(
unwrap(list)).getElementType());
69 ModuleOp modOp =
unwrap(cMod);
71 mlir::parseSourceFile<ModuleOp>(
unwrap(filename), modOp.getContext());
72 Block *loadedBlock = loadedMod->getBody();
73 assert(!modOp->getRegions().empty());
74 if (modOp.getBodyRegion().empty()) {
75 modOp.getBodyRegion().push_back(loadedBlock);
78 auto &ops = modOp.getBody()->getOperations();
79 ops.splice(ops.end(), loadedBlock->getOperations());
90 [genFunc, userData](ServiceImplementReqOp req,
91 ServiceDeclOpInterface decl, ServiceImplRecordOp) {
92 return unwrap(genFunc(
wrap(req),
wrap(decl.getOperation()), userData));
100 return isa<ChannelBundleType>(
unwrap(type));
106 SmallVector<BundledChannel, 4> channelsVector(llvm::map_range(
107 ArrayRef<CirctESIBundleTypeBundleChannel>(channels, numChannels),
111 cast<ChannelType>(
unwrap(channel.channelType))};
117 return cast<ChannelBundleType>(
unwrap(bundle)).getResettable() != UnitAttr();
120 return cast<ChannelBundleType>(
unwrap(bundle)).getChannels().size();
125 cast<ChannelBundleType>(
unwrap(bundle)).getChannels()[idx];
135 return isa<AppIDAttr>(
unwrap(attr));
151 std::optional<uint64_t> index = cast<AppIDAttr>(
unwrap(attr)).getIndex();
154 *indexOut = index.value();
159 return isa<AppIDPathAttr>(
unwrap(attr));
164 MlirAttribute
const *cElements) {
165 SmallVector<AppIDAttr, 8> elements;
167 elements.push_back(cast<AppIDAttr>(
unwrap(cElements[i])));
172 return wrap(cast<AppIDPathAttr>(
unwrap(attr)).getRoot());
175 return cast<AppIDPathAttr>(
unwrap(attr)).getPath().size();
179 return wrap(cast<AppIDPathAttr>(
unwrap(attr)).getPath()[index]);
198 MLIR_CAPI_EXPORTED MlirAttribute
200 auto mod = cast<hw::HWModuleLike>(
unwrap(op));
201 return wrap(
unwrap(idx)->getChildAppIDsOf(mod));
206 MlirOperation fromMod,
209 auto mod = cast<hw::HWModuleLike>(
unwrap(fromMod));
210 auto path = cast<AppIDAttr>(
unwrap(appid));
213 if (failed(instPath))
214 return MlirAttribute{
nullptr};
215 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)
MlirOperation circtESILookup(MlirModule mod, MlirStringRef symbol)
MLIR_CAPI_EXPORTED void circtESIAppIDIndexFree(CirctESIAppIDIndex index)
Free an AppIDIndex.
MlirType circtESIChannelTypeGet(MlirType inner, uint32_t signaling)
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.
MlirAttribute circtESIAppIDAttrGet(MlirContext ctxt, MlirStringRef name, uint64_t index)
MlirAttribute circtESIAppIDAttrGetNoIdx(MlirContext ctxt, MlirStringRef name)
MlirLogicalResult(* CirctESIServiceGeneratorFunc)(MlirOperation serviceImplementReqOp, MlirOperation declOp, 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