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"
30 return isa<ChannelType>(
unwrap(type));
35 auto signalEnum = symbolizeChannelSignaling(signaling);
38 auto cppInner =
unwrap(inner);
39 return wrap(ChannelType::get(cppInner.getContext(), cppInner, *signalEnum,
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);
66 return wrap(ListType::get(cppInner.getContext(), cppInner));
70 return wrap(cast<ListType>(
unwrap(list)).getElementType());
78 ModuleOp modOp =
unwrap(cMod);
80 mlir::parseSourceFile<ModuleOp>(
unwrap(filename), modOp.getContext());
81 Block *loadedBlock = loadedMod->getBody();
82 assert(!modOp->getRegions().empty());
83 if (modOp.getBodyRegion().empty()) {
84 modOp.getBodyRegion().push_back(loadedBlock);
87 auto &ops = modOp.getBody()->getOperations();
88 ops.splice(ops.end(), loadedBlock->getOperations());
98 unwrap(impl_type), [genFunc, userData](ServiceImplementReqOp req,
99 ServiceDeclOpInterface decl,
100 ServiceImplRecordOp record) {
102 wrap(record.getOperation()), userData));
110 return isa<ChannelBundleType>(
unwrap(type));
115 MLIRContext *ctxt =
unwrap(cctxt);
116 SmallVector<BundledChannel, 4> channelsVector(llvm::map_range(
117 ArrayRef<CirctESIBundleTypeBundleChannel>(channels, numChannels),
121 cast<ChannelType>(
unwrap(channel.channelType))};
123 return wrap(ChannelBundleType::get(
124 ctxt, channelsVector, resettable ? UnitAttr::get(ctxt) : UnitAttr()));
127 return cast<ChannelBundleType>(
unwrap(bundle)).getResettable() != UnitAttr();
130 return cast<ChannelBundleType>(
unwrap(bundle)).getChannels().size();
135 cast<ChannelBundleType>(
unwrap(bundle)).getChannels()[idx];
145 return isa<AppIDAttr>(
unwrap(attr));
150 return wrap(AppIDAttr::get(
154 return wrap(AppIDAttr::get(
158 return wrap(cast<AppIDAttr>(
unwrap(attr)).getName().getValue());
161 std::optional<uint64_t> index = cast<AppIDAttr>(
unwrap(attr)).getIndex();
164 *indexOut = index.value();
169 return isa<AppIDPathAttr>(
unwrap(attr));
174 MlirAttribute
const *cElements) {
175 SmallVector<AppIDAttr, 8> elements;
177 elements.push_back(cast<AppIDAttr>(
unwrap(cElements[i])));
178 return wrap(AppIDPathAttr::get(
179 unwrap(ctxt), cast<FlatSymbolRefAttr>(
unwrap(root)), elements));
182 return wrap(cast<AppIDPathAttr>(
unwrap(attr)).getRoot());
185 return cast<AppIDPathAttr>(
unwrap(attr)).getPath().size();
189 return wrap(cast<AppIDPathAttr>(
unwrap(attr)).getPath()[index]);
208MLIR_CAPI_EXPORTED MlirAttribute
210 auto mod = cast<hw::HWModuleLike>(
unwrap(op));
211 return wrap(
unwrap(idx)->getChildAppIDsOf(mod));
216 MlirOperation fromMod,
219 auto mod = cast<hw::HWModuleLike>(
unwrap(fromMod));
220 auto path = cast<AppIDAttr>(
unwrap(appid));
221 FailureOr<ArrayAttr> instPath =
223 if (failed(instPath))
224 return MlirAttribute{
nullptr};
225 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)
bool circtESICheckInnerTypeMatch(MlirType to, MlirType from)
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.
LogicalResult checkInnerTypeMatch(Type expected, Type actual)
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
ChannelDirection direction