MLIR 22.0.0git
LowerVectorStep.cpp
Go to the documentation of this file.
1//===- LowerVectorStep.cpp - Lower 'vector.step' operation ----------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements target-independent rewrites and utilities to lower the
10// 'vector.step' operation.
11//
12//===----------------------------------------------------------------------===//
13
18
19#define DEBUG_TYPE "vector-step-lowering"
20
21using namespace mlir;
22using namespace mlir::vector;
23
24namespace {
25
26struct StepToArithConstantOpRewrite final : OpRewritePattern<vector::StepOp> {
27 using Base::Base;
28
29 LogicalResult matchAndRewrite(vector::StepOp stepOp,
30 PatternRewriter &rewriter) const override {
31 auto resultType = cast<VectorType>(stepOp.getType());
32 if (resultType.isScalable()) {
33 return failure();
34 }
35 int64_t elementCount = resultType.getNumElements();
37 llvm::map_to_vector(llvm::seq(elementCount),
38 [](int64_t i) { return APInt(/*width=*/64, i); });
39 rewriter.replaceOpWithNewOp<arith::ConstantOp>(
40 stepOp, DenseElementsAttr::get(resultType, indices));
41 return success();
42 }
43};
44} // namespace
45
48 patterns.add<StepToArithConstantOpRewrite>(patterns.getContext(), benefit);
49}
return success()
static DenseElementsAttr get(ShapedType type, ArrayRef< Attribute > values)
Constructs a dense elements attribute from an array of element values.
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...
OpTy replaceOpWithNewOp(Operation *op, Args &&...args)
Replace the results of the given (original) op with a new op that is created without verification (re...
void populateVectorStepLoweringPatterns(RewritePatternSet &patterns, PatternBenefit benefit=1)
Populate the pattern set with the following patterns:
Include the generated interface declarations.
const FrozenRewritePatternSet & patterns
OpRewritePattern is a wrapper around RewritePattern that allows for matching and rewriting against an...