summaryrefslogtreecommitdiff
path: root/mlir/test/lib/Transforms/TestCommutativityUtils.cpp
blob: 5ea35759bb7298656c662b43afda785439e36889 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//===- TestCommutativityUtils.cpp - Pass to test the commutativity utility-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This pass tests the functionality of the commutativity utility pattern.
//
//===----------------------------------------------------------------------===//

#include "mlir/Transforms/CommutativityUtils.h"

#include "TestDialect.h"
#include "mlir/Pass/Pass.h"
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"

using namespace mlir;

namespace {

struct CommutativityUtils
    : public PassWrapper<CommutativityUtils, OperationPass<func::FuncOp>> {
  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(CommutativityUtils)

  StringRef getArgument() const final { return "test-commutativity-utils"; }
  StringRef getDescription() const final {
    return "Test the functionality of the commutativity utility";
  }

  void runOnOperation() override {
    auto func = getOperation();
    auto *context = &getContext();

    RewritePatternSet patterns(context);
    populateCommutativityUtilsPatterns(patterns);

    (void)applyPatternsGreedily(func, std::move(patterns));
  }
};
} // namespace

namespace mlir {
namespace test {
void registerCommutativityUtils() { PassRegistration<CommutativityUtils>(); }
} // namespace test
} // namespace mlir