9 #include "mlir/CAPI/IR.h"
10 #include "mlir/CAPI/Registration.h"
11 #include "mlir/CAPI/Support.h"
12 #include "mlir/CAPI/Utils.h"
13 #include "mlir/IR/Builders.h"
14 #include "mlir/IR/SymbolTable.h"
15 #include "mlir/Parser/Parser.h"
16 #include "mlir/Support/FileUtilities.h"
18 using namespace circt;
26 return unwrap(type).isa<ChannelType>();
30 auto signalEnum = symbolizeChannelSignaling(signaling);
33 auto cppInner =
unwrap(inner);
38 return wrap(
unwrap(channelType).cast<ChannelType>().getInner());
41 return (uint32_t)
unwrap(channelType).cast<ChannelType>().getSignaling();
45 return unwrap(type).isa<AnyType>();
52 return unwrap(type).isa<ListType>();
56 auto cppInner =
unwrap(inner);
61 return wrap(
unwrap(list).cast<ListType>().getElementType());
65 ModuleOp modOp =
unwrap(cMod);
67 mlir::parseSourceFile<ModuleOp>(
unwrap(filename), modOp.getContext());
68 Block *loadedBlock = loadedMod->getBody();
69 assert(!modOp->getRegions().empty());
70 if (modOp.getBodyRegion().empty()) {
71 modOp.getBodyRegion().push_back(loadedBlock);
74 auto &ops = modOp.getBody()->getOperations();
75 ops.splice(ops.end(), loadedBlock->getOperations());
85 unwrap(impl_type), [genFunc, userData](ServiceImplementReqOp req,
86 ServiceDeclOpInterface decl) {
87 return unwrap(genFunc(
wrap(req),
wrap(decl.getOperation()), userData));
95 return isa<ChannelBundleType>(
unwrap(type));
100 MLIRContext *ctxt =
unwrap(cctxt);
101 SmallVector<BundledChannel, 4> channelsVector(llvm::map_range(
102 ArrayRef<CirctESIBundleTypeBundleChannel>(channels, numChannels),
106 cast<ChannelType>(
unwrap(channel.channelType))};
109 ctxt, channelsVector, resettable ?
UnitAttr::get(ctxt) : UnitAttr()));
112 return cast<ChannelBundleType>(
unwrap(bundle)).getResettable() != UnitAttr();
115 return cast<ChannelBundleType>(
unwrap(bundle)).getChannels().size();
120 cast<ChannelBundleType>(
unwrap(bundle)).getChannels()[idx];
130 return unwrap(attr).isa<AppIDAttr>();
142 std::optional<uint64_t> index =
unwrap(attr).cast<AppIDAttr>().getIndex();
145 *indexOut = index.value();
150 return isa<AppIDPathAttr>(
unwrap(attr));
155 MlirAttribute
const *cElements) {
156 SmallVector<AppIDAttr, 8> elements;
158 elements.push_back(cast<AppIDAttr>(
unwrap(cElements[i])));
160 unwrap(ctxt), cast<FlatSymbolRefAttr>(
unwrap(root)), elements));
163 return wrap(cast<AppIDPathAttr>(
unwrap(attr)).getRoot());
166 return cast<AppIDPathAttr>(
unwrap(attr)).getPath().size();
170 return wrap(cast<AppIDPathAttr>(
unwrap(attr)).getPath()[index]);
189 MLIR_CAPI_EXPORTED MlirAttribute
191 auto mod = cast<hw::HWModuleLike>(
unwrap(op));
192 return wrap(
unwrap(idx)->getChildAppIDsOf(mod));
197 MlirOperation fromMod,
200 auto mod = cast<hw::HWModuleLike>(
unwrap(fromMod));
201 auto path = cast<AppIDAttr>(
unwrap(appid));
204 if (failed(instPath))
205 return MlirAttribute{
nullptr};
206 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)
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.
This file defines an intermediate representation for circuits acting as an abstraction for constraint...
ChannelDirection direction