19#define DEBUG_TYPE "vector-step-lowering"
26struct StepToArithConstantOpRewrite final :
OpRewritePattern<vector::StepOp> {
27 StepToArithConstantOpRewrite(
MLIRContext *context,
unsigned indexBitwidth,
30 assert(indexBitwidth <= IndexType::kInternalStorageBitWidth &&
31 "indexBitwidth cannot exceed the index storage bitwidth");
34 LogicalResult matchAndRewrite(vector::StepOp stepOp,
36 auto resultType = cast<VectorType>(stepOp.getType());
37 if (resultType.isScalable()) {
40 Type elementType = resultType.getElementType();
44 if (elementType.
isIndex() && indexBitwidth == 0) {
50 unsigned computeWidth = elementType.
isIndex()
53 unsigned storageWidth = elementType.
isIndex()
54 ? IndexType::kInternalStorageBitWidth
56 int64_t elementCount = resultType.getNumElements();
58 llvm::seq(elementCount), [computeWidth, storageWidth](
int64_t i) {
59 return APInt(computeWidth, i,
false,
68 unsigned indexBitwidth;
75 patterns.
add<StepToArithConstantOpRewrite>(patterns.
getContext(),
76 indexBitwidth, benefit);
static DenseElementsAttr get(ShapedType type, ArrayRef< Attribute > values)
Constructs a dense elements attribute from an array of element values.
MLIRContext is the top-level object for a collection of MLIR operations.
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.
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...
unsigned getIntOrFloatBitWidth() const
Return the bit width of an integer or a float type, assert failure on other types.
void populateVectorStepLoweringPatterns(RewritePatternSet &patterns, unsigned indexBitwidth=64, PatternBenefit benefit=1)
Populate the pattern set with the following patterns:
Include the generated interface declarations.
OpRewritePattern is a wrapper around RewritePattern that allows for matching and rewriting against an...