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<WindowType>(
unwrap(type));
149 MlirType into,
size_t numFrames,
150 const MlirType *cFrames) {
151 MLIRContext *ctxt =
unwrap(cctxt);
152 SmallVector<WindowFrameType, 4> frames;
153 for (
size_t i = 0; i < numFrames; ++i)
154 frames.push_back(cast<WindowFrameType>(
unwrap(cFrames[i])));
155 return wrap(WindowType::get(ctxt, cast<StringAttr>(
unwrap(name)),
160 return wrap((Attribute)cast<WindowType>(
unwrap(window)).getName());
164 return wrap(cast<WindowType>(
unwrap(window)).getInto());
168 return cast<WindowType>(
unwrap(window)).getFrames().size();
172 return wrap(cast<WindowType>(
unwrap(window)).getFrames()[idx]);
176 return wrap(cast<WindowType>(
unwrap(window)).getLoweredType());
180 return isa<WindowFrameType>(
unwrap(type));
185 const MlirType *cMembers) {
186 MLIRContext *ctxt =
unwrap(cctxt);
187 SmallVector<WindowFieldType, 4> members;
188 for (
size_t i = 0; i < numMembers; ++i)
189 members.push_back(cast<WindowFieldType>(
unwrap(cMembers[i])));
191 WindowFrameType::get(ctxt, cast<StringAttr>(
unwrap(name)), members));
195 return wrap((Attribute)cast<WindowFrameType>(
unwrap(frame)).getName());
199 return cast<WindowFrameType>(
unwrap(frame)).getMembers().size();
203 return wrap(cast<WindowFrameType>(
unwrap(frame)).getMembers()[idx]);
207 return isa<WindowFieldType>(
unwrap(type));
212 return wrap(WindowFieldType::get(
213 unwrap(cctxt), cast<StringAttr>(
unwrap(fieldName)), numItems));
221 return cast<WindowFieldType>(
unwrap(field)).getNumItems();
229 return isa<AppIDAttr>(
unwrap(attr));
234 return wrap(AppIDAttr::get(
238 return wrap(AppIDAttr::get(
242 return wrap(cast<AppIDAttr>(
unwrap(attr)).getName().getValue());
245 std::optional<uint64_t> index = cast<AppIDAttr>(
unwrap(attr)).getIndex();
248 *indexOut = index.value();
253 return isa<AppIDPathAttr>(
unwrap(attr));
258 MlirAttribute
const *cElements) {
259 SmallVector<AppIDAttr, 8> elements;
261 elements.push_back(cast<AppIDAttr>(
unwrap(cElements[i])));
262 return wrap(AppIDPathAttr::get(
263 unwrap(ctxt), cast<FlatSymbolRefAttr>(
unwrap(root)), elements));
266 return wrap(cast<AppIDPathAttr>(
unwrap(attr)).getRoot());
269 return cast<AppIDPathAttr>(
unwrap(attr)).getPath().size();
273 return wrap(cast<AppIDPathAttr>(
unwrap(attr)).getPath()[index]);
292MLIR_CAPI_EXPORTED MlirAttribute
294 auto mod = cast<hw::HWModuleLike>(
unwrap(op));
295 return wrap(
unwrap(idx)->getChildAppIDsOf(mod));
300 MlirOperation fromMod,
303 auto mod = cast<hw::HWModuleLike>(
unwrap(fromMod));
304 auto path = cast<AppIDAttr>(
unwrap(appid));
305 FailureOr<ArrayAttr> instPath =
307 if (failed(instPath))
308 return MlirAttribute{
nullptr};
309 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 circtESIWindowTypeGetLoweredType(MlirType window)
MlirType circtESIAnyTypeGet(MlirContext ctxt)
bool circtESIAppIDAttrGetIndex(MlirAttribute attr, uint64_t *indexOut)
MlirType circtESIWindowTypeGet(MlirContext cctxt, MlirAttribute name, MlirType into, size_t numFrames, const MlirType *cFrames)
bool circtESITypeIsAnAnyType(MlirType type)
MlirType circtESIWindowFrameTypeGet(MlirContext cctxt, MlirAttribute name, size_t numMembers, const MlirType *cMembers)
MLIR_CAPI_EXPORTED MlirAttribute circtESIAppIDIndexGetAppIDPath(CirctESIAppIDIndex idx, MlirOperation fromMod, MlirAttribute appid, MlirLocation loc)
bool circtESIBundleTypeGetResettable(MlirType bundle)
bool circtESITypeIsAWindowFrameType(MlirType type)
uint64_t circtESIWindowFieldTypeGetNumItems(MlirType field)
void circtESIAppendMlirFile(MlirModule cMod, MlirStringRef filename)
MlirType circtESIWindowFrameTypeGetMember(MlirType frame, size_t idx)
MlirType circtESIChannelGetInner(MlirType channelType)
bool circtESITypeIsABundleType(MlirType type)
bool circtESICheckInnerTypeMatch(MlirType to, MlirType from)
MlirAttribute circtESIWindowFrameTypeGetName(MlirType frame)
uint64_t circtESIAppIDAttrPathGetNumComponents(MlirAttribute attr)
uint64_t circtESIChannelGetDataDelay(MlirType channelType)
MlirOperation circtESILookup(MlirModule mod, MlirStringRef symbol)
MlirType circtESIWindowTypeGetInto(MlirType window)
MLIR_CAPI_EXPORTED void circtESIAppIDIndexFree(CirctESIAppIDIndex index)
Free an AppIDIndex.
MlirAttribute circtESIWindowTypeGetName(MlirType window)
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)
MlirType circtESIWindowTypeGetFrame(MlirType window, size_t idx)
bool circtESIAttributeIsAnAppIDAttr(MlirAttribute attr)
size_t circtESIWindowTypeGetNumFrames(MlirType window)
uint32_t circtESIChannelGetSignaling(MlirType channelType)
MlirType circtESIWindowFieldTypeGet(MlirContext cctxt, MlirAttribute fieldName, uint64_t numItems)
size_t circtESIWindowFrameTypeGetNumMembers(MlirType frame)
bool circtESITypeIsAWindowType(MlirType type)
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 circtESITypeIsAWindowFieldType(MlirType type)
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 circtESIWindowFieldTypeGetFieldName(MlirType field)
MlirAttribute circtESIAppIDAttrGetNoIdx(MlirContext ctxt, MlirStringRef name)
MlirLogicalResult(* CirctESIServiceGeneratorFunc)(MlirOperation serviceImplementReqOp, MlirOperation declOp, MlirOperation recordOp, void *userData)
static bool getFieldName(const FieldRef &fieldRef, SmallString< 32 > &string)
static EvaluatorValuePtr unwrap(OMEvaluatorValue c)
DEFINE_C_API_PTR_METHODS(SynthLongestPathHistory, llvm::ImmutableListImpl< DebugPoint >) llvm
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