MLIR  20.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 
17 #include "mlir/IR/PatternMatch.h"
18 
19 #define DEBUG_TYPE "vector-step-lowering"
20 
21 using namespace mlir;
22 using namespace mlir::vector;
23 
24 namespace {
25 
26 struct StepToArithConstantOpRewrite final : OpRewritePattern<vector::StepOp> {
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();
36  SmallVector<APInt> indices =
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 }
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...
Definition: PatternMatch.h:34
A special type of RewriterBase that coordinates the application of a rewrite pattern on the current I...
Definition: PatternMatch.h:791
OpTy replaceOpWithNewOp(Operation *op, Args &&...args)
Replace the results of the given (original) op with a new op that is created without verification (re...
Definition: PatternMatch.h:542
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...
Definition: PatternMatch.h:358
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...
Definition: PatternMatch.h:362