1 //===- TestCommutativityUtils.cpp - Pass to test the commutativity utility-===// 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 pass tests the functionality of the commutativity utility pattern. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #include "mlir/Transforms/CommutativityUtils.h" 14 15 #include "TestDialect.h" 16 #include "mlir/Pass/Pass.h" 17 #include "mlir/Transforms/GreedyPatternRewriteDriver.h" 18 19 using namespace mlir; 20 21 namespace { 22 23 struct CommutativityUtils 24 : public PassWrapper<CommutativityUtils, OperationPass<func::FuncOp>> { 25 MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(CommutativityUtils) 26 27 StringRef getArgument() const final { return "test-commutativity-utils"; } 28 StringRef getDescription() const final { 29 return "Test the functionality of the commutativity utility"; 30 } 31 32 void runOnOperation() override { 33 auto func = getOperation(); 34 auto *context = &getContext(); 35 36 RewritePatternSet patterns(context); 37 populateCommutativityUtilsPatterns(patterns); 38 39 (void)applyPatternsGreedily(func, std::move(patterns)); 40 } 41 }; 42 } // namespace 43 44 namespace mlir { 45 namespace test { 46 void registerCommutativityUtils() { PassRegistration<CommutativityUtils>(); } 47 } // namespace test 48 } // namespace mlir 49