32 if (convertedTypes.empty())
36 TypeRange convertedTypeRange(convertedTypes);
44 builder, loc, convertedTypeRange, value);
56 struct DecomposeCallGraphTypesForFuncArgs
61 matchAndRewrite(func::FuncOp op, OpAdaptor adaptor,
63 auto functionType = op.getFunctionType();
69 if (failed(typeConverter->convertType(argType.value(), decomposedTypes)))
71 if (!decomposedTypes.empty())
72 conversion.addInputs(argType.index(), decomposedTypes);
76 if (failed(rewriter.convertRegionTypes(&op.getBody(), *getTypeConverter(),
82 if (failed(typeConverter->convertTypes(functionType.getResults(),
85 rewriter.modifyOpInPlace(op, [&] {
86 op.setType(rewriter.getFunctionType(conversion.getConvertedTypes(),
100 struct DecomposeCallGraphTypesForReturnOp
105 matchAndRewrite(ReturnOp op, OpAdaptor adaptor,
108 for (
Value operand : adaptor.getOperands()) {
111 llvm::append_range(newOperands,
113 getTypeConverter()));
115 rewriter.replaceOpWithNewOp<ReturnOp>(op, newOperands);
131 matchAndRewrite(CallOp op, OpAdaptor adaptor,
136 for (
Value operand : adaptor.getOperands()) {
139 llvm::append_range(newOperands,
141 getTypeConverter()));
148 for (
Type resultType : op.getResultTypes()) {
149 unsigned oldSize = newResultTypes.size();
150 if (failed(typeConverter->convertType(resultType, newResultTypes)))
152 expandedResultSizes.push_back(newResultTypes.size() - oldSize);
155 CallOp newCallOp = rewriter.create<CallOp>(op.getLoc(), op.getCalleeAttr(),
156 newResultTypes, newOperands);
160 replacedValues.reserve(op.getNumResults());
161 unsigned startIdx = 0;
162 for (
unsigned i = 0, e = op.getNumResults(); i < e; ++i) {
164 newCallOp.getResults().slice(startIdx, expandedResultSizes[i]);
165 replacedValues.push_back(repl);
166 startIdx += expandedResultSizes[i];
168 rewriter.replaceOpWithMultiple(op, replacedValues);
178 .
add<DecomposeCallGraphTypesForCallOp, DecomposeCallGraphTypesForFuncArgs,
179 DecomposeCallGraphTypesForReturnOp>(typeConverter, context);
static SmallVector< Value > decomposeValue(OpBuilder &builder, Location loc, Value value, const TypeConverter *converter)
If the given value can be decomposed with the type converter, decompose it.
This class implements a pattern rewriter for use with ConversionPatterns.
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
MLIRContext is the top-level object for a collection of MLIR operations.
This class helps build Operations.
OpConversionPattern is a wrapper around ConversionPattern that allows for matching and rewriting agai...
OpConversionPattern(MLIRContext *context, PatternBenefit benefit=1)
RewritePatternSet & add(ConstructorArg &&arg, ConstructorArgs &&...args)
Add an instance of each of the pattern types 'Ts' to the pattern list with the given arguments.
This class provides all of the information necessary to convert a type signature.
LogicalResult convertType(Type t, SmallVectorImpl< Type > &results) const
Convert the given type.
Value materializeTargetConversion(OpBuilder &builder, Location loc, Type resultType, ValueRange inputs, Type originalType={}) const
This class provides an abstraction over the various different ranges of value types.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
This class provides an abstraction over the different types of ranges over Values.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Type getType() const
Return the type of this value.
constexpr void enumerate(std::tuple< Tys... > &tuple, CallbackT &&callback)
Include the generated interface declarations.
void populateDecomposeCallGraphTypesPatterns(MLIRContext *context, const TypeConverter &typeConverter, RewritePatternSet &patterns)
Populates the patterns needed to drive the conversion process for decomposing call graph types with t...