36 #define DEBUG_TYPE "vector-broadcast-lowering"
47 LogicalResult matchAndRewrite(vector::BroadcastOp op,
49 auto loc = op.getLoc();
50 VectorType dstType = op.getResultVectorType();
51 VectorType srcType = dyn_cast<VectorType>(op.getSourceType());
52 Type eltType = dstType.getElementType();
61 int64_t srcRank = srcType.getRank();
62 int64_t dstRank = dstType.getRank();
65 if (srcRank <= 1 && dstRank == 1) {
68 ext = rewriter.
create<vector::ExtractElementOp>(loc, op.getSource());
70 ext = rewriter.
create<vector::ExtractOp>(loc, op.getSource(), 0);
84 if (srcRank < dstRank) {
88 rewriter.
create<vector::BroadcastOp>(loc, resType, op.getSource());
91 for (int64_t d = 0, dim = dstType.getDimSize(0); d < dim; ++d)
92 result = rewriter.
create<vector::InsertOp>(loc, bcst, result, d);
98 assert(srcRank == dstRank);
100 for (int64_t r = 0; r < dstRank; r++)
101 if (srcType.getDimSize(r) != dstType.getDimSize(r)) {
129 dstType.getScalableDims().drop_front());
134 Value ext = rewriter.
create<vector::ExtractOp>(loc, op.getSource(), 0);
135 Value bcst = rewriter.
create<vector::BroadcastOp>(loc, resType, ext);
136 for (int64_t d = 0, dim = dstType.getDimSize(0); d < dim; ++d)
137 result = rewriter.
create<vector::InsertOp>(loc, bcst, result, d);
140 if (dstType.getScalableDims()[0]) {
144 for (int64_t d = 0, dim = dstType.getDimSize(0); d < dim; ++d) {
145 Value ext = rewriter.
create<vector::ExtractOp>(loc, op.getSource(), d);
146 Value bcst = rewriter.
create<vector::BroadcastOp>(loc, resType, ext);
147 result = rewriter.
create<vector::InsertOp>(loc, bcst, result, d);
158 patterns.
add<BroadcastOpLowering>(patterns.
getContext(), benefit);
TypedAttr getZeroAttr(Type type)
Operation * create(const OperationState &state)
Creates an operation given the fields represented as an OperationState.
This class represents the benefit of a pattern match in a unitless scheme that ranges from 0 (very li...
A special type of RewriterBase that coordinates the application of a rewrite pattern on the current I...
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.
virtual void replaceOp(Operation *op, ValueRange newValues)
Replace the results of the given (original) operation with the specified list of values (replacements...
OpTy replaceOpWithNewOp(Operation *op, Args &&...args)
Replace the results of the given (original) op with a new op that is created without verification (re...
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
This is a builder type that keeps local references to arguments.
Builder & dropDim(unsigned pos)
Erase a dim from shape @pos.
void populateVectorBroadcastLoweringPatterns(RewritePatternSet &patterns, PatternBenefit benefit=1)
Populate the pattern set with the following patterns:
Include the generated interface declarations.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
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...