19#define GEN_PASS_DEF_SHAPETOSHAPELOWERINGPASS
20#include "mlir/Dialect/Shape/Transforms/Passes.h.inc"
32 LogicalResult matchAndRewrite(NumElementsOp op,
33 PatternRewriter &rewriter)
const final;
38NumElementsOpConverter::matchAndRewrite(NumElementsOp op,
40 auto loc = op.getLoc();
41 Type valueType = op.getResult().getType();
42 Value init = op->getDialect()
43 ->materializeConstant(rewriter, rewriter.
getIndexAttr(1),
46 ReduceOp
reduce = ReduceOp::create(rewriter, loc, op.getShape(), init);
53 shape::YieldOp::create(
b, loc,
product);
60struct ShapeToShapeLowering
61 :
public impl::ShapeToShapeLoweringPassBase<ShapeToShapeLowering> {
62 void runOnOperation()
override;
66void ShapeToShapeLowering::runOnOperation() {
73 target.addLegalDialect<arith::ArithDialect, ShapeDialect>();
74 target.addIllegalOp<NumElementsOp>();
75 if (
failed(mlir::applyPartialConversion(getOperation(),
target,
static int64_t product(ArrayRef< int64_t > vals)
static Value reduce(OpBuilder &builder, Location loc, Value input, Value output, int64_t dim)
BlockArgument getArgument(unsigned i)
IntegerAttr getIndexAttr(int64_t value)
static OpBuilder atBlockEnd(Block *block, Listener *listener=nullptr)
Create a builder and set the insertion point to after the last operation in the block but still insid...
A special type of RewriterBase that coordinates the application of a rewrite pattern on the current I...
virtual void replaceOp(Operation *op, ValueRange newValues)
Replace the results of the given (original) operation with the specified list of values (replacements...
Include the generated interface declarations.
void populateShapeRewritePatterns(RewritePatternSet &patterns)
Collects a set of patterns to rewrite ops within the Shape dialect.
const FrozenRewritePatternSet & patterns
OpRewritePattern is a wrapper around RewritePattern that allows for matching and rewriting against an...
OpRewritePattern(MLIRContext *context, PatternBenefit benefit=1, ArrayRef< StringRef > generatedNames={})
Patterns must specify the root operation name they match against, and can also specify the benefit of...