MLIR 22.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//===----------------------------------------------------------------------===//
13#ifndef MLIR_DIALECT_GPU_TRANSFORMS_PASSES_H_
14#define MLIR_DIALECT_GPU_TRANSFORMS_PASSES_H_
20#include "mlir/Pass/Pass.h"
21#include <optional>
22
23namespace llvm {
24class TargetMachine;
25class LLVMContext;
26class Module;
27} // namespace llvm
28
29namespace mlir {
30class TypeConverter;
31class ConversionTarget;
32namespace func {
33class 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.
40void populateGpuGlobalIdPatterns(RewritePatternSet &patterns);
41
42/// Collect a set of patterns to rewrite SubgroupIdOp op within the GPU
43/// dialect.
44void populateGpuSubgroupIdPatterns(RewritePatternSet &patterns);
45
46/// Collect a set of patterns to rewrite shuffle ops within the GPU dialect.
47void populateGpuShufflePatterns(RewritePatternSet &patterns);
48
49/// Collect a set of patterns to rewrite all-reduce ops within the GPU dialect.
50void 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.
96
97namespace 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.
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.
112
113/// Erase barriers that do not enforce conflicting memory side effects.
115
116/// Tries to promote `gpu.shuffle`s to specialized AMDGPU intrinsics.
118 RewritePatternSet &patterns, std::optional<amdgpu::Chipset> maybeChipset);
119
120/// Generate the code for registering passes.
121#define GEN_PASS_REGISTRATION
122#include "mlir/Dialect/GPU/Transforms/Passes.h.inc"
123
124} // namespace mlir
125
126#endif // MLIR_DIALECT_GPU_TRANSFORMS_PASSES_H_
static llvm::ManagedStatic< PassManagerOptions > options
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 populateGpuPromoteShuffleToAMDGPUPatterns(RewritePatternSet &patterns, std::optional< amdgpu::Chipset > maybeChipset)
Tries to promote gpu.shuffles to specialized AMDGPU intrinsics.
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....