12 using namespace circt;
18 llvm::SmallVector<Type> res, arg;
19 llvm::transform(type.getResults(), std::back_inserter(res),
20 [&](Type t) { return typeConverter.convertType(t); });
21 llvm::transform(type.getInputs(), std::back_inserter(arg),
22 [&](Type t) { return typeConverter.convertType(t); });
29 hw::ModuleType type) {
31 SmallVector<hw::ModulePort> ports(type.getPorts());
33 p.type = typeConverter.convertType(p.type);
38 ConversionPatternRewriter &rewriter,
39 const TypeConverter *typeConverter) {
41 llvm::SmallVector<NamedAttribute, 4> newAttrs;
42 newAttrs.reserve(op->getAttrs().size());
43 for (
auto attr : op->getAttrs()) {
44 if (
auto typeAttr = dyn_cast<TypeAttr>(attr.getValue())) {
48 if (
auto funcType = dyn_cast<FunctionType>(
innerType))
50 else if (
auto modType = dyn_cast<hw::ModuleType>(
innerType))
56 newAttrs.push_back(attr);
61 llvm::SmallVector<Type, 4> newResults;
62 if (failed(typeConverter->convertTypes(op->getResultTypes(), newResults)))
63 return rewriter.notifyMatchFailure(op->getLoc(),
"type conversion failed");
66 OperationState state(op->getLoc(), op->getName().getStringRef(), operands,
67 newResults, newAttrs, op->getSuccessors());
68 for (
size_t i = 0, e = op->getNumRegions(); i < e; ++i)
73 Operation *newOp = rewriter.create(state);
76 rewriter.startOpModification(newOp);
77 for (
size_t i = 0, e = op->getNumRegions(); i < e; ++i) {
78 Region ®ion = op->getRegion(i);
79 Region *newRegion = &newOp->getRegion(i);
82 rewriter.inlineRegionBefore(region, *newRegion, newRegion->begin());
83 TypeConverter::SignatureConversion result(newRegion->getNumArguments());
84 if (failed(typeConverter->convertSignatureArgs(
85 newRegion->getArgumentTypes(), result)))
86 return rewriter.notifyMatchFailure(op->getLoc(),
87 "type conversion failed");
88 if (failed(rewriter.convertRegionTypes(newRegion, *typeConverter, &result)))
91 rewriter.finalizeOpModification(newOp);
93 rewriter.replaceOp(op, newOp->getResults());
static FunctionType convertFunctionType(const TypeConverter &typeConverter, FunctionType type)
static hw::ModuleType convertModuleType(const TypeConverter &typeConverter, hw::ModuleType type)
Direction get(bool isOutput)
Returns an output direction if isOutput is true, otherwise returns an input direction.
mlir::Type innerType(mlir::Type type)
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
LogicalResult doTypeConversion(Operation *op, ValueRange operands, ConversionPatternRewriter &rewriter, const TypeConverter *typeConverter)