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); });
24 return FunctionType::get(type.getContext(), arg, res);
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())) {
45 auto innerType = typeAttr.getValue();
48 if (
auto funcType = dyn_cast<FunctionType>(innerType))
50 else if (
auto modType = dyn_cast<hw::ModuleType>(innerType))
53 innerType = typeConverter->convertType(innerType);
54 newAttrs.emplace_back(attr.getName(), TypeAttr::get(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());