24 matchAndRewrite(CallOp callOp, OpAdaptor adaptor,
28 if (failed(typeConverter->convertTypes(callOp.getResultTypes(),
34 if (callOp->getNumResults() != convertedResults.size())
40 callOp, callOp.getCallee(), convertedResults, adaptor.getOperands());
48 patterns.
add<CallOpSignatureConversion>(converter, patterns.
getContext());
55 class BranchOpInterfaceTypeConversion
61 BranchOpInterfaceTypeConversion(
63 function_ref<
bool(BranchOpInterface,
int)> shouldConvertBranchOperand)
65 shouldConvertBranchOperand(shouldConvertBranchOperand) {}
73 for (
int succIdx = 0, succEnd = op->getBlock()->getNumSuccessors();
74 succIdx < succEnd; ++succIdx) {
76 op.getSuccessorOperands(succIdx).getForwardedOperands();
77 if (forwardedOperands.empty())
81 eidx = idx + forwardedOperands.size();
83 if (!shouldConvertBranchOperand || shouldConvertBranchOperand(op, idx))
84 newOperands[idx] = operands[idx];
88 op, [newOperands, op]() { op->setOperands(newOperands); });
93 function_ref<bool(BranchOpInterface,
int)> shouldConvertBranchOperand;
106 matchAndRewrite(ReturnOp op, OpAdaptor adaptor,
111 [&] { op->setOperands(adaptor.getOperands()); });
119 function_ref<
bool(BranchOpInterface,
int)> shouldConvertBranchOperand) {
120 patterns.
add<BranchOpInterfaceTypeConversion>(
121 typeConverter, patterns.
getContext(), shouldConvertBranchOperand);
127 if (
auto branchOp = dyn_cast<BranchOpInterface>(op)) {
129 auto successorOperands = branchOp.getSuccessorOperands(p);
131 successorOperands.getForwardedOperands().getTypes()))
142 patterns.
add<ReturnOpTypeConversion>(typeConverter, patterns.
getContext());
150 if (isa<ReturnOp>(op) && !returnOpAlwaysLegal)
166 if (!block || &block->
back() != op)
Block represents an ordered list of Operations.
unsigned getNumSuccessors()
This class implements a pattern rewriter for use with ConversionPatterns.
MLIRContext is the top-level object for a collection of MLIR operations.
OpConversionPattern is a wrapper around ConversionPattern that allows for matching and rewriting agai...
OpInterfaceConversionPattern is a wrapper around ConversionPattern that allows for matching and rewri...
This class provides the API for ops that are known to be terminators.
This class implements the operand iterators for the Operation class.
unsigned getBeginOperandIndex() const
Return the operand index of the first element of this range.
Operation is the basic unit of execution within MLIR.
bool hasTrait()
Returns true if the operation was registered with a particular trait, e.g.
bool mightHaveTrait()
Returns true if the operation might have the provided trait.
Operation * getParentOp()
Returns the closest surrounding operation that contains this operation or nullptr if this is a top-le...
Block * getBlock()
Returns the operation block that contains this operation.
MLIRContext * getContext() const
RewritePatternSet & add(ConstructorArg &&arg, ConstructorArgs &&...args)
Add an instance of each of the pattern types 'Ts' to the pattern list with the given arguments.
void modifyOpInPlace(Operation *root, CallableT &&callable)
This method is a utility wrapper around an in-place modification of an operation.
OpTy replaceOpWithNewOp(Operation *op, Args &&...args)
Replace the results of the given (original) op with a new op that is created without verification (re...
bool isLegal(Type type) const
Return true if the given type is legal for this type converter, i.e.
Include the generated interface declarations.
bool isLegalForReturnOpTypeConversionPattern(Operation *op, const TypeConverter &converter, bool returnOpAlwaysLegal=false)
For ReturnLike ops (except return), return True.
bool isNotBranchOpInterfaceOrReturnLikeOp(Operation *op)
Return true if op is neither BranchOpInterface nor ReturnLike.
void populateBranchOpInterfaceTypeConversionPattern(RewritePatternSet &patterns, const TypeConverter &converter, function_ref< bool(BranchOpInterface branchOp, int idx)> shouldConvertBranchOperand=nullptr)
Add a pattern to the given pattern list to rewrite branch operations to use operands that have been l...
void populateCallOpTypeConversionPattern(RewritePatternSet &patterns, const TypeConverter &converter)
Add a pattern to the given pattern list to convert the operand and result types of a CallOp with the ...
void populateReturnOpTypeConversionPattern(RewritePatternSet &patterns, const TypeConverter &converter)
Add a pattern to the given pattern list to rewrite return ops to use operands that have been legalize...
bool isLegalForBranchOpInterfaceTypeConversionPattern(Operation *op, const TypeConverter &converter)
Return true if op is a BranchOpInterface op whose operands are all legal according to converter.
This trait indicates that a terminator operation is "return-like".