1 //===- TestCommutativityUtils.cpp - Pass to test the commutativity utility-===//
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 // This pass tests the functionality of the commutativity utility pattern.
11 //===----------------------------------------------------------------------===//
13 #include "mlir/Transforms/CommutativityUtils.h"
15 #include "TestDialect.h"
16 #include "mlir/Pass/Pass.h"
17 #include "mlir/Transforms/GreedyPatternRewriteDriver.h"
23 struct CommutativityUtils
24 : public PassWrapper
<CommutativityUtils
, OperationPass
<func::FuncOp
>> {
25 MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(CommutativityUtils
)
27 StringRef
getArgument() const final
{ return "test-commutativity-utils"; }
28 StringRef
getDescription() const final
{
29 return "Test the functionality of the commutativity utility";
32 void runOnOperation() override
{
33 auto func
= getOperation();
34 auto *context
= &getContext();
36 RewritePatternSet
patterns(context
);
37 populateCommutativityUtilsPatterns(patterns
);
39 (void)applyPatternsAndFoldGreedily(func
, std::move(patterns
));
46 void registerCommutativityUtils() { PassRegistration
<CommutativityUtils
>(); }