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) {}
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,
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());
147 bool returnOpAlwaysLegal) {
151 if (isa<ReturnOp>(op) && !returnOpAlwaysLegal)
167 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.
operand_iterator operand_begin()
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.
operand_iterator operand_end()
void setOperands(ValueRange operands)
Replace the current operands of this operation with the ones provided in 'operands'.
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 updateRootInPlace(Operation *root, CallableT &&callable)
This method is a utility wrapper around a root update of an operation.
OpTy replaceOpWithNewOp(Operation *op, Args &&...args)
Replaces the result op with a new op that is created without verification.
bool isLegal(Type type) const
Return true if the given type is legal for this type converter, i.e.
Include the generated interface declarations.
LogicalResult failure(bool isFailure=true)
Utility function to generate a LogicalResult.
void populateCallOpTypeConversionPattern(RewritePatternSet &patterns, 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, TypeConverter &converter)
Add a pattern to the given pattern list to rewrite return ops to use operands that have been legalize...
void populateBranchOpInterfaceTypeConversionPattern(RewritePatternSet &patterns, 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...
LogicalResult success(bool isSuccess=true)
Utility function to generate a LogicalResult.
bool isNotBranchOpInterfaceOrReturnLikeOp(Operation *op)
Return true if op is neither BranchOpInterface nor ReturnLike.
bool isLegalForReturnOpTypeConversionPattern(Operation *op, TypeConverter &converter, bool returnOpAlwaysLegal=false)
For ReturnLike ops (except return), return True.
bool failed(LogicalResult result)
Utility function that returns true if the provided LogicalResult corresponds to a failure value.
bool isLegalForBranchOpInterfaceTypeConversionPattern(Operation *op, TypeConverter &converter)
Return true if op is a BranchOpInterface op whose operands are all legal according to converter.
This class represents an efficient way to signal success or failure.
This trait indicates that a terminator operation is "return-like".