MLIR 24.0.0git
GPUToNVVMPipeline.cpp
Go to the documentation of this file.
1//===- GPUToNVVMPipeline.cpp - Test lowering to NVVM as a sink pass -------===//
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 implements a pass for testing the lowering to NVVM as a generally
10// usable sink pass.
11//
12//===----------------------------------------------------------------------===//
13
34
35using namespace mlir;
36
37namespace {
38
39//===----------------------------------------------------------------------===//
40// Common pipeline
41//===----------------------------------------------------------------------===//
42void buildCommonPassPipeline(
44 pm.addPass(createConvertNVGPUToNVVMPass());
45 pm.addPass(createGpuKernelOutliningPass());
47 pm.addPass(createSCFToControlFlowPass());
48 pm.addPass(createConvertNVVMToLLVMPass());
49 pm.addPass(createConvertFuncToLLVMPass());
50 pm.addPass(memref::createExpandStridedMetadataPass());
51
52 GpuNVVMAttachTargetOptions nvvmTargetOptions;
53 nvvmTargetOptions.triple = options.cubinTriple;
54 nvvmTargetOptions.chip = options.cubinChip;
55 nvvmTargetOptions.features = options.cubinFeatures;
56 nvvmTargetOptions.optLevel = options.optLevel;
57 nvvmTargetOptions.cmdOptions = options.cmdOptions;
58 pm.addPass(createGpuNVVMAttachTarget(nvvmTargetOptions));
59 pm.addPass(createLowerAffinePass());
60 pm.addPass(createArithToLLVMConversionPass());
61 ConvertIndexToLLVMPassOptions convertIndexToLLVMPassOpt;
62 convertIndexToLLVMPassOpt.indexBitwidth = options.indexBitWidth;
63 pm.addPass(createConvertIndexToLLVMPass(convertIndexToLLVMPassOpt));
65 pm.addPass(createCSEPass());
66}
67
68//===----------------------------------------------------------------------===//
69// GPUModule-specific stuff.
70//===----------------------------------------------------------------------===//
71void buildGpuPassPipeline(OpPassManager &pm,
73 ConvertGpuOpsToNVVMOpsOptions opt;
74 opt.useBarePtrCallConv = options.kernelUseBarePtrCallConv;
75 opt.indexBitwidth = options.indexBitWidth;
76 opt.allowPatternRollback = options.allowPatternRollback;
77 pm.addNestedPass<gpu::GPUModuleOp>(createConvertGpuOpsToNVVMOps(opt));
78 pm.addNestedPass<gpu::GPUModuleOp>(createCanonicalizerPass());
79 pm.addNestedPass<gpu::GPUModuleOp>(createCSEPass());
80 pm.addNestedPass<gpu::GPUModuleOp>(createReconcileUnrealizedCastsPass());
81}
82
83//===----------------------------------------------------------------------===//
84// Host Post-GPU pipeline
85//===----------------------------------------------------------------------===//
86void buildHostPostPipeline(OpPassManager &pm,
88 GpuToLLVMConversionPassOptions opt;
89 opt.hostBarePtrCallConv = options.hostUseBarePtrCallConv;
90 opt.kernelBarePtrCallConv = options.kernelUseBarePtrCallConv;
91 pm.addPass(createGpuToLLVMConversionPass(opt));
92
93 GpuAttachSelectObjectPassOptions gpuAttachSelectObjectPassOptions;
94 gpuAttachSelectObjectPassOptions.priority = options.defaultCtorPriority;
95 pm.addPass(createGpuAttachSelectObjectPass(gpuAttachSelectObjectPassOptions));
96
97 GpuModuleToBinaryPassOptions gpuModuleToBinaryPassOptions;
98 gpuModuleToBinaryPassOptions.compilationTarget = options.cubinFormat;
99 pm.addPass(createGpuModuleToBinaryPass(gpuModuleToBinaryPassOptions));
100 pm.addPass(createConvertMathToLLVMPass());
102 pm.addPass(createCSEPass());
103 pm.addPass(createReconcileUnrealizedCastsPass());
104}
105
106} // namespace
107
110 // Common pipelines
111 buildCommonPassPipeline(pm, options);
112
113 // GPUModule-specific stuff
114 buildGpuPassPipeline(pm, options);
115
116 // Host post-GPUModule-specific stuff
117 buildHostPostPipeline(pm, options);
118}
119
122 "gpu-lower-to-nvvm-pipeline",
123 "The default pipeline lowers main dialects (arith, memref, scf, "
124 "vector, gpu, and nvgpu) to NVVM. It starts by lowering GPU code to the "
125 "specified compilation target (default is fatbin) then lowers the host "
126 "code.",
128}
static llvm::ManagedStatic< PassManagerOptions > options
This class represents a pass manager that runs passes on either a specific operation type,...
Definition PassManager.h:46
void addPass(std::unique_ptr< Pass > pass)
Add the given pass to this pass manager.
Definition Pass.cpp:393
void addNestedPass(std::unique_ptr< Pass > pass)
Add the given pass to a nested pass manager for the given operation kind OpT.
void registerGPUToNVVMPipeline()
Register all pipelines for the gpu dialect.
void buildLowerToNVVMPassPipeline(OpPassManager &pm, const GPUToNVVMPipelineOptions &options)
Adds the GPU to NVVM pipeline to the given pass manager.
Include the generated interface declarations.
std::unique_ptr< Pass > createCanonicalizerPass(const GreedyRewriteConfig &config, ArrayRef< std::string > disabledPatterns={}, ArrayRef< std::string > enabledPatterns={})
Creates an instance of the Canonicalizer pass with the specified config.
std::unique_ptr< Pass > createConvertVectorToSCFPass(const VectorTransferToSCFOptions &options=VectorTransferToSCFOptions())
Create a pass to convert a subset of vector ops to SCF.
PassPipelineRegistration provides a global initializer that registers a Pass pipeline builder routine...
Options for the gpu to nvvm pipeline.
Definition Passes.h:19