23 for (
auto &conversion : decomposeValueConversions)
24 if (conversion(builder, loc, type, value, results))
26 results.push_back(value);
36 template <
typename SourceOp>
37 class DecomposeCallGraphTypesOpConversionPattern
40 DecomposeCallGraphTypesOpConversionPattern(
TypeConverter &typeConverter,
45 decomposer(decomposer) {}
59 struct DecomposeCallGraphTypesForFuncArgs
60 :
public DecomposeCallGraphTypesOpConversionPattern<func::FuncOp> {
61 using DecomposeCallGraphTypesOpConversionPattern::
62 DecomposeCallGraphTypesOpConversionPattern;
65 matchAndRewrite(func::FuncOp op, OpAdaptor adaptor,
67 auto functionType = op.getFunctionType();
73 if (
failed(typeConverter->convertType(argType.value(), decomposedTypes)))
75 if (!decomposedTypes.empty())
76 conversion.addInputs(argType.index(), decomposedTypes);
80 if (
failed(rewriter.convertRegionTypes(&op.getBody(), *getTypeConverter(),
86 if (
failed(typeConverter->convertTypes(functionType.getResults(),
89 rewriter.modifyOpInPlace(op, [&] {
90 op.setType(rewriter.getFunctionType(conversion.getConvertedTypes(),
105 struct DecomposeCallGraphTypesForReturnOp
106 :
public DecomposeCallGraphTypesOpConversionPattern<ReturnOp> {
107 using DecomposeCallGraphTypesOpConversionPattern::
108 DecomposeCallGraphTypesOpConversionPattern;
110 matchAndRewrite(ReturnOp op, OpAdaptor adaptor,
113 for (
Value operand : adaptor.getOperands())
114 decomposer.decomposeValue(rewriter, op.
getLoc(), operand.getType(),
115 operand, newOperands);
116 rewriter.replaceOpWithNewOp<ReturnOp>(op, newOperands);
129 struct DecomposeCallGraphTypesForCallOp
130 :
public DecomposeCallGraphTypesOpConversionPattern<CallOp> {
131 using DecomposeCallGraphTypesOpConversionPattern::
132 DecomposeCallGraphTypesOpConversionPattern;
135 matchAndRewrite(CallOp op, OpAdaptor adaptor,
140 for (
Value operand : adaptor.getOperands())
141 decomposer.decomposeValue(rewriter, op.
getLoc(), operand.getType(),
142 operand, newOperands);
152 unsigned oldSize = newResultTypes.size();
153 if (
failed(typeConverter->convertType(resultType, newResultTypes)))
155 auto &resultMapping = expandedResultIndices.emplace_back();
156 for (
unsigned i = oldSize, e = newResultTypes.size(); i < e; i++)
157 resultMapping.push_back(i);
160 CallOp newCallOp = rewriter.create<CallOp>(op.
getLoc(), op.getCalleeAttr(),
161 newResultTypes, newOperands);
169 auto decomposedValues = llvm::to_vector<6>(
170 llvm::map_range(expandedResultIndices[i],
171 [&](
unsigned i) {
return newCallOp.getResult(i); }));
172 if (decomposedValues.empty()) {
174 replacedValues.push_back(
nullptr);
175 }
else if (decomposedValues.size() == 1) {
176 replacedValues.push_back(decomposedValues.front());
179 Value materialized = getTypeConverter()->materializeArgumentConversion(
180 rewriter, op.
getLoc(), op.getType(i), decomposedValues);
181 replacedValues.push_back(materialized);
184 rewriter.replaceOp(op, replacedValues);
194 .
add<DecomposeCallGraphTypesForCallOp, DecomposeCallGraphTypesForFuncArgs,
195 DecomposeCallGraphTypesForReturnOp>(typeConverter, context,
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...
Location getLoc()
The source location the operation was defined or derived from.
result_type_range getResultTypes()
unsigned getNumResults()
Return the number of results held by this operation.
This class represents the benefit of a pattern match in a unitless scheme that ranges from 0 (very li...
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.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
This class provides a hook that expands one Value into multiple Value's, with a TypeConverter-inspire...
void decomposeValue(OpBuilder &, Location, Type, Value, SmallVectorImpl< Value > &)
This method tries to decompose a value of a certain type using provided decompose callback functions.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
constexpr void enumerate(std::tuple< Tys... > &tuple, CallbackT &&callback)
Include the generated interface declarations.
LogicalResult failure(bool isFailure=true)
Utility function to generate a LogicalResult.
LogicalResult success(bool isSuccess=true)
Utility function to generate a LogicalResult.
void populateDecomposeCallGraphTypesPatterns(MLIRContext *context, TypeConverter &typeConverter, ValueDecomposer &decomposer, RewritePatternSet &patterns)
Populates the patterns needed to drive the conversion process for decomposing call graph types with t...
bool failed(LogicalResult result)
Utility function that returns true if the provided LogicalResult corresponds to a failure value.
This class represents an efficient way to signal success or failure.