1 //===- TestAllReduceLowering.cpp - Test gpu.all_reduce lowering -----------===//
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 file contains test passes for lowering the gpu.all_reduce op.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "mlir/Dialect/GPU/Passes.h"
14 #include "mlir/Dialect/MemRef/IR/MemRef.h"
15 #include "mlir/Dialect/StandardOps/IR/Ops.h"
16 #include "mlir/Pass/Pass.h"
17 #include "mlir/Transforms/GreedyPatternRewriteDriver.h"
18 
19 using namespace mlir;
20 
21 namespace {
22 struct TestGpuRewritePass
23     : public PassWrapper<TestGpuRewritePass, OperationPass<ModuleOp>> {
24   void getDependentDialects(DialectRegistry &registry) const override {
25     registry.insert<StandardOpsDialect, memref::MemRefDialect>();
26   }
27   StringRef getArgument() const final { return "test-gpu-rewrite"; }
28   StringRef getDescription() const final {
29     return "Applies all rewrite patterns within the GPU dialect.";
30   }
31   void runOnOperation() override {
32     RewritePatternSet patterns(&getContext());
33     populateGpuRewritePatterns(patterns);
34     (void)applyPatternsAndFoldGreedily(getOperation(), std::move(patterns));
35   }
36 };
37 } // namespace
38 
39 namespace mlir {
40 void registerTestAllReduceLoweringPass() {
41   PassRegistration<TestGpuRewritePass>();
42 }
43 } // namespace mlir
44