32 matchAndRewrite(func::CallOp callOp, OpAdaptor adaptor,
35 if (callOp.getNumResults() > 1)
37 callOp,
"only functions with zero or one result can be converted");
40 adaptor.getOperands(),
52 matchAndRewrite(func::FuncOp funcOp, OpAdaptor adaptor,
55 if (funcOp.getFunctionType().getNumResults() > 1)
57 funcOp,
"only functions with zero or one result can be converted");
60 emitc::FuncOp newFuncOp = rewriter.
create<emitc::FuncOp>(
61 funcOp.getLoc(), funcOp.getName(), funcOp.getFunctionType());
64 for (
const auto &namedAttr : funcOp->getAttrs()) {
65 if (namedAttr.getName() != funcOp.getFunctionTypeAttrName() &&
67 newFuncOp->
setAttr(namedAttr.getName(), namedAttr.getValue());
71 if (funcOp.isDeclaration()) {
73 newFuncOp.setSpecifiersAttr(specifiers);
78 if (funcOp.isPrivate() && !funcOp.isDeclaration()) {
80 newFuncOp.setSpecifiersAttr(specifiers);
83 if (!funcOp.isDeclaration())
97 matchAndRewrite(func::ReturnOp returnOp, OpAdaptor adaptor,
99 if (returnOp.getNumOperands() > 1)
101 returnOp,
"only zero or one operand is supported");
105 returnOp.getNumOperands() ? adaptor.getOperands()[0] :
nullptr);
118 patterns.add<CallOpConversion, FuncOpConversion, ReturnOpConversion>(ctx);
ArrayAttr getStrArrayAttr(ArrayRef< StringRef > values)
This class implements a pattern rewriter for use with ConversionPatterns.
void eraseOp(Operation *op) override
PatternRewriter hook for erasing a dead operation.
MLIRContext is the top-level object for a collection of MLIR operations.
Operation * create(const OperationState &state)
Creates an operation given the fields represented as an OperationState.
OpConversionPattern is a wrapper around ConversionPattern that allows for matching and rewriting agai...
void setAttr(StringAttr name, Attribute value)
If the an attribute exists with the specified name, change it to the new value.
std::enable_if_t<!std::is_convertible< CallbackT, Twine >::value, LogicalResult > notifyMatchFailure(Location loc, CallbackT &&reasonCallback)
Used to notify the listener that the IR failed to be rewritten because of a match failure,...
void inlineRegionBefore(Region ®ion, Region &parent, Region::iterator before)
Move the blocks that belong to "region" before the given position in another region "parent".
OpTy replaceOpWithNewOp(Operation *op, Args &&...args)
Replace the results of the given (original) op with a new op that is created without verification (re...
static StringRef getSymbolAttrName()
Return the name of the attribute used for symbol names.
Include the generated interface declarations.
void populateFuncToEmitCPatterns(RewritePatternSet &patterns)
const FrozenRewritePatternSet & patterns