MLIR  21.0.0git
Passes.h
Go to the documentation of this file.
1 //===- Passes.h - Pass Entrypoints ------------------------------*- C++ -*-===//
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 header file defines prototypes that expose pass constructors.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef MLIR_DIALECT_GPU_TRANSFORMS_PASSES_H_
14 #define MLIR_DIALECT_GPU_TRANSFORMS_PASSES_H_
15 
19 #include "mlir/IR/PatternMatch.h"
20 #include "mlir/Pass/Pass.h"
21 #include <optional>
22 
23 namespace llvm {
24 class TargetMachine;
25 class LLVMContext;
26 class Module;
27 } // namespace llvm
28 
29 namespace mlir {
30 class TypeConverter;
31 class ConversionTarget;
32 namespace func {
33 class FuncOp;
34 } // namespace func
35 
36 #define GEN_PASS_DECL
37 #include "mlir/Dialect/GPU/Transforms/Passes.h.inc"
38 
39 /// Collect a set of patterns to rewrite GlobalIdOp op within the GPU dialect.
40 void populateGpuGlobalIdPatterns(RewritePatternSet &patterns);
41 
42 /// Collect a set of patterns to rewrite SubgroupIdOp op within the GPU
43 /// dialect.
44 void populateGpuSubgroupIdPatterns(RewritePatternSet &patterns);
45 
46 /// Collect a set of patterns to rewrite shuffle ops within the GPU dialect.
47 void populateGpuShufflePatterns(RewritePatternSet &patterns);
48 
49 /// Collect a set of patterns to rewrite all-reduce ops within the GPU dialect.
50 void populateGpuAllReducePatterns(RewritePatternSet &patterns);
51 
52 /// Collect a set of patterns to break down subgroup_reduce ops into smaller
53 /// ones supported by the target of `size <= maxShuffleBitwidth`, where `size`
54 /// is the subgroup_reduce value bitwidth.
56  RewritePatternSet &patterns, unsigned maxShuffleBitwidth = 32,
57  PatternBenefit benefit = 1);
58 
59 /// Collect a set of patterns to lower `gpu.subgroup_reduce` into `gpu.shuffle`
60 /// ops over `shuffleBitwidth` scalar types. Assumes that the subgroup has
61 /// `subgroupSize` lanes. Uses the butterfly shuffle algorithm.
62 ///
63 /// The patterns populated by this function will ignore ops with the
64 /// `cluster_size` attribute.
65 /// `populateGpuLowerClusteredSubgroupReduceToShufflePatterns` is the opposite.
67  RewritePatternSet &patterns, unsigned subgroupSize,
68  unsigned shuffleBitwidth = 32, PatternBenefit benefit = 1);
69 
70 /// Disjoint counterpart of `populateGpuLowerSubgroupReduceToShufflePatterns`
71 /// that only matches `gpu.subgroup_reduce` ops with a `cluster_size`.
73  RewritePatternSet &patterns, unsigned subgroupSize,
74  unsigned shuffleBitwidth = 32, PatternBenefit benefit = 1);
75 
76 /// Collect a set of patterns to lower `gpu.subgroup_reduce` into `amdgpu.dpp`
77 /// ops over scalar types. Assumes that the subgroup has
78 /// `subgroupSize` lanes. Applicable only to AMD GPUs.
80  unsigned subgroupSize,
81  amdgpu::Chipset chipset,
82  PatternBenefit benefit = 1);
83 
84 /// Disjoint counterpart of `populateGpuLowerSubgroupReduceToDPPPatterns`
85 /// that only matches `gpu.subgroup_reduce` ops with a `cluster_size`.
87  RewritePatternSet &patterns, unsigned subgroupSize, amdgpu::Chipset chipset,
88  PatternBenefit benefit = 1);
89 
90 /// Collect all patterns to rewrite ops within the GPU dialect.
95 }
96 
97 namespace gpu {
98 /// Searches for all GPU modules in `op` and transforms them into GPU binary
99 /// operations. The resulting `gpu.binary` has `handler` as its offloading
100 /// handler attribute.
101 LogicalResult transformGpuModulesToBinaries(
102  Operation *op, OffloadingLLVMTranslationAttrInterface handler = nullptr,
103  const gpu::TargetOptions &options = {});
104 } // namespace gpu
105 
106 //===----------------------------------------------------------------------===//
107 // Registration
108 //===----------------------------------------------------------------------===//
109 
110 /// Collect a set of patterns to decompose memrefs ops.
111 void populateGpuDecomposeMemrefsPatterns(RewritePatternSet &patterns);
112 
113 /// Erase barriers that do not enforce conflicting memory side effects.
114 void populateGpuEliminateBarriersPatterns(RewritePatternSet &patterns);
115 
116 /// Generate the code for registering passes.
117 #define GEN_PASS_REGISTRATION
118 #include "mlir/Dialect/GPU/Transforms/Passes.h.inc"
119 
120 } // namespace mlir
121 
122 #endif // MLIR_DIALECT_GPU_TRANSFORMS_PASSES_H_
static llvm::ManagedStatic< PassManagerOptions > options
constexpr unsigned subgroupSize
HW dependent constants.
The OpAsmOpInterface, see OpAsmInterface.td for more details.
Definition: CallGraph.h:229
LogicalResult transformGpuModulesToBinaries(Operation *op, OffloadingLLVMTranslationAttrInterface handler=nullptr, const gpu::TargetOptions &options={})
Searches for all GPU modules in op and transforms them into GPU binary operations.
Include the generated interface declarations.
void populateGpuShufflePatterns(RewritePatternSet &patterns)
Collect a set of patterns to rewrite shuffle ops within the GPU dialect.
void populateGpuGlobalIdPatterns(RewritePatternSet &patterns)
Collect a set of patterns to rewrite GlobalIdOp op within the GPU dialect.
void populateGpuRewritePatterns(RewritePatternSet &patterns)
Collect all patterns to rewrite ops within the GPU dialect.
Definition: Passes.h:91
void populateGpuLowerSubgroupReduceToShufflePatterns(RewritePatternSet &patterns, unsigned subgroupSize, unsigned shuffleBitwidth=32, PatternBenefit benefit=1)
Collect a set of patterns to lower gpu.subgroup_reduce into gpu.shuffle ops over shuffleBitwidth scal...
void populateGpuLowerClusteredSubgroupReduceToShufflePatterns(RewritePatternSet &patterns, unsigned subgroupSize, unsigned shuffleBitwidth=32, PatternBenefit benefit=1)
Disjoint counterpart of populateGpuLowerSubgroupReduceToShufflePatterns that only matches gpu....
const FrozenRewritePatternSet & patterns
void populateGpuAllReducePatterns(RewritePatternSet &patterns)
Collect a set of patterns to rewrite all-reduce ops within the GPU dialect.
void populateGpuBreakDownSubgroupReducePatterns(RewritePatternSet &patterns, unsigned maxShuffleBitwidth=32, PatternBenefit benefit=1)
Collect a set of patterns to break down subgroup_reduce ops into smaller ones supported by the target...
void populateGpuDecomposeMemrefsPatterns(RewritePatternSet &patterns)
Collect a set of patterns to decompose memrefs ops.
void populateGpuLowerSubgroupReduceToDPPPatterns(RewritePatternSet &patterns, unsigned subgroupSize, amdgpu::Chipset chipset, PatternBenefit benefit=1)
Collect a set of patterns to lower gpu.subgroup_reduce into amdgpu.dpp ops over scalar types.
void populateGpuSubgroupIdPatterns(RewritePatternSet &patterns)
Collect a set of patterns to rewrite SubgroupIdOp op within the GPU dialect.
void populateGpuEliminateBarriersPatterns(RewritePatternSet &patterns)
Erase barriers that do not enforce conflicting memory side effects.
void populateGpuLowerClusteredSubgroupReduceToDPPPatterns(RewritePatternSet &patterns, unsigned subgroupSize, amdgpu::Chipset chipset, PatternBenefit benefit=1)
Disjoint counterpart of populateGpuLowerSubgroupReduceToDPPPatterns that only matches gpu....