xref: /llvm-project/mlir/test/lib/Transforms/TestCommutativityUtils.cpp (revision 09dfc5713d7e2342bea4c8447d1ed76c85eb8225)
1b508c564Ssrishti-cb //===- TestCommutativityUtils.cpp - Pass to test the commutativity utility-===//
2b508c564Ssrishti-cb //
3b508c564Ssrishti-cb // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4b508c564Ssrishti-cb // See https://llvm.org/LICENSE.txt for license information.
5b508c564Ssrishti-cb // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6b508c564Ssrishti-cb //
7b508c564Ssrishti-cb //===----------------------------------------------------------------------===//
8b508c564Ssrishti-cb //
9b508c564Ssrishti-cb // This pass tests the functionality of the commutativity utility pattern.
10b508c564Ssrishti-cb //
11b508c564Ssrishti-cb //===----------------------------------------------------------------------===//
12b508c564Ssrishti-cb 
13b508c564Ssrishti-cb #include "mlir/Transforms/CommutativityUtils.h"
14b508c564Ssrishti-cb 
15b508c564Ssrishti-cb #include "TestDialect.h"
16b508c564Ssrishti-cb #include "mlir/Pass/Pass.h"
17b508c564Ssrishti-cb #include "mlir/Transforms/GreedyPatternRewriteDriver.h"
18b508c564Ssrishti-cb 
19b508c564Ssrishti-cb using namespace mlir;
20b508c564Ssrishti-cb 
21b508c564Ssrishti-cb namespace {
22b508c564Ssrishti-cb 
23b508c564Ssrishti-cb struct CommutativityUtils
24b508c564Ssrishti-cb     : public PassWrapper<CommutativityUtils, OperationPass<func::FuncOp>> {
25b508c564Ssrishti-cb   MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(CommutativityUtils)
26b508c564Ssrishti-cb 
27b508c564Ssrishti-cb   StringRef getArgument() const final { return "test-commutativity-utils"; }
28b508c564Ssrishti-cb   StringRef getDescription() const final {
29b508c564Ssrishti-cb     return "Test the functionality of the commutativity utility";
30b508c564Ssrishti-cb   }
31b508c564Ssrishti-cb 
32b508c564Ssrishti-cb   void runOnOperation() override {
33b508c564Ssrishti-cb     auto func = getOperation();
34b508c564Ssrishti-cb     auto *context = &getContext();
35b508c564Ssrishti-cb 
36b508c564Ssrishti-cb     RewritePatternSet patterns(context);
37b508c564Ssrishti-cb     populateCommutativityUtilsPatterns(patterns);
38b508c564Ssrishti-cb 
39*09dfc571SJacques Pienaar     (void)applyPatternsGreedily(func, std::move(patterns));
40b508c564Ssrishti-cb   }
41b508c564Ssrishti-cb };
42b508c564Ssrishti-cb } // namespace
43b508c564Ssrishti-cb 
44b508c564Ssrishti-cb namespace mlir {
45b508c564Ssrishti-cb namespace test {
46b508c564Ssrishti-cb void registerCommutativityUtils() { PassRegistration<CommutativityUtils>(); }
47b508c564Ssrishti-cb } // namespace test
48b508c564Ssrishti-cb } // namespace mlir
49