1 //===- TestMemRefStrideCalculation.cpp - Pass to test strides computation--===//
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
7 //===----------------------------------------------------------------------===//
9 #include "mlir/Dialect/MemRef/IR/MemRef.h"
10 #include "mlir/IR/BuiltinTypes.h"
11 #include "mlir/Pass/Pass.h"
16 struct TestMemRefStrideCalculation
17 : public PassWrapper
<TestMemRefStrideCalculation
,
18 InterfacePass
<SymbolOpInterface
>> {
19 MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestMemRefStrideCalculation
)
21 StringRef
getArgument() const final
{
22 return "test-memref-stride-calculation";
24 StringRef
getDescription() const final
{
25 return "Test operation constant folding";
27 void runOnOperation() override
;
31 /// Traverse AllocOp and compute strides of each MemRefType independently.
32 void TestMemRefStrideCalculation::runOnOperation() {
33 llvm::outs() << "Testing: " << getOperation().getName() << "\n";
34 getOperation().walk([&](memref::AllocOp allocOp
) {
35 auto memrefType
= allocOp
.getResult().getType().cast
<MemRefType
>();
37 SmallVector
<int64_t, 4> strides
;
38 if (failed(getStridesAndOffset(memrefType
, strides
, offset
))) {
39 llvm::outs() << "MemRefType " << memrefType
<< " cannot be converted to "
43 llvm::outs() << "MemRefType offset: ";
44 if (ShapedType::isDynamic(offset
))
47 llvm::outs() << offset
;
48 llvm::outs() << " strides: ";
49 llvm::interleaveComma(strides
, llvm::outs(), [&](int64_t v
) {
50 if (ShapedType::isDynamic(v
))
62 void registerTestMemRefStrideCalculation() {
63 PassRegistration
<TestMemRefStrideCalculation
>();