14 #include "mlir/Transforms/DialectConversion.h"
16 using namespace circt;
24 const TypeConverter &typeConverter,
25 ConversionPatternRewriter &rewriter) {
26 ModuleType type = modOp.getHWModuleType();
32 SmallVector<ModulePort> newPorts;
33 TypeConverter::SignatureConversion result(type.getNumInputs());
35 unsigned curInputs = 0;
36 for (
auto &p : type.getPorts()) {
38 SmallVector<Type, 1> newResults;
39 if (failed(typeConverter.convertType(p.type, newResults)))
41 for (
auto np : newResults)
42 newPorts.push_back({p.name, np, p.dir});
44 if (failed(typeConverter.convertSignatureArg(
51 for (
auto np : result.getConvertedTypes().drop_front(curInputs))
52 newPorts.push_back({p.name, np, p.dir});
53 curInputs = result.getConvertedTypes().size();
57 if (failed(rewriter.convertRegionTypes(&modOp->getRegion(0), typeConverter,
62 rewriter.modifyOpInPlace(modOp, [&] { modOp.setHWModuleType(newType); });
71 struct HWModuleLikeSignatureConversion :
public ConversionPattern {
72 HWModuleLikeSignatureConversion(StringRef moduleLikeOpName, MLIRContext *ctx,
73 const TypeConverter &converter)
74 : ConversionPattern(converter, moduleLikeOpName, 1, ctx) {}
77 matchAndRewrite(Operation *op, ArrayRef<Value> ,
78 ConversionPatternRewriter &rewriter)
const override {
79 HWModuleLike modOp = cast<HWModuleLike>(op);
86 StringRef moduleLikeOpName, RewritePatternSet &
patterns,
87 TypeConverter &converter) {
88 patterns.add<HWModuleLikeSignatureConversion>(
89 moduleLikeOpName,
patterns.getContext(), converter);
static LogicalResult convertModuleOpTypes(HWModuleLike modOp, const TypeConverter &typeConverter, ConversionPatternRewriter &rewriter)
Direction get(bool isOutput)
Returns an output direction if isOutput is true, otherwise returns an input direction.
void populateHWModuleLikeTypeConversionPattern(StringRef moduleLikeOpName, RewritePatternSet &patterns, TypeConverter &converter)
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.