MLIR  22.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 
30 #include "mlir/Pass/PassManager.h"
31 #include "mlir/Pass/PassOptions.h"
32 #include "mlir/Transforms/Passes.h"
33 
34 using namespace mlir;
35 
36 namespace {
37 
38 //===----------------------------------------------------------------------===//
39 // Common pipeline
40 //===----------------------------------------------------------------------===//
41 void buildCommonPassPipeline(
43  pm.addPass(createConvertNVGPUToNVVMPass());
44  pm.addPass(createGpuKernelOutliningPass());
46  pm.addPass(createSCFToControlFlowPass());
47  pm.addPass(createConvertNVVMToLLVMPass());
48  pm.addPass(createConvertFuncToLLVMPass());
49  pm.addPass(memref::createExpandStridedMetadataPass());
50 
51  GpuNVVMAttachTargetOptions nvvmTargetOptions;
52  nvvmTargetOptions.triple = options.cubinTriple;
53  nvvmTargetOptions.chip = options.cubinChip;
54  nvvmTargetOptions.features = options.cubinFeatures;
55  nvvmTargetOptions.optLevel = options.optLevel;
56  nvvmTargetOptions.cmdOptions = options.cmdOptions;
57  pm.addPass(createGpuNVVMAttachTarget(nvvmTargetOptions));
58  pm.addPass(createLowerAffinePass());
59  pm.addPass(createArithToLLVMConversionPass());
60  ConvertIndexToLLVMPassOptions convertIndexToLLVMPassOpt;
61  convertIndexToLLVMPassOpt.indexBitwidth = options.indexBitWidth;
62  pm.addPass(createConvertIndexToLLVMPass(convertIndexToLLVMPassOpt));
64  pm.addPass(createCSEPass());
65 }
66 
67 //===----------------------------------------------------------------------===//
68 // GPUModule-specific stuff.
69 //===----------------------------------------------------------------------===//
70 void buildGpuPassPipeline(OpPassManager &pm,
72  ConvertGpuOpsToNVVMOpsOptions opt;
73  opt.useBarePtrCallConv = options.kernelUseBarePtrCallConv;
74  opt.indexBitwidth = options.indexBitWidth;
75  pm.addNestedPass<gpu::GPUModuleOp>(createConvertGpuOpsToNVVMOps(opt));
76  pm.addNestedPass<gpu::GPUModuleOp>(createCanonicalizerPass());
77  pm.addNestedPass<gpu::GPUModuleOp>(createCSEPass());
78  pm.addNestedPass<gpu::GPUModuleOp>(createReconcileUnrealizedCastsPass());
79 }
80 
81 //===----------------------------------------------------------------------===//
82 // Host Post-GPU pipeline
83 //===----------------------------------------------------------------------===//
84 void buildHostPostPipeline(OpPassManager &pm,
86  GpuToLLVMConversionPassOptions opt;
87  opt.hostBarePtrCallConv = options.hostUseBarePtrCallConv;
88  opt.kernelBarePtrCallConv = options.kernelUseBarePtrCallConv;
89  pm.addPass(createGpuToLLVMConversionPass(opt));
90 
91  GpuModuleToBinaryPassOptions gpuModuleToBinaryPassOptions;
92  gpuModuleToBinaryPassOptions.compilationTarget = options.cubinFormat;
93  pm.addPass(createGpuModuleToBinaryPass(gpuModuleToBinaryPassOptions));
94  pm.addPass(createConvertMathToLLVMPass());
96  pm.addPass(createCSEPass());
97  pm.addPass(createReconcileUnrealizedCastsPass());
98 }
99 
100 } // namespace
101 
104  // Common pipelines
105  buildCommonPassPipeline(pm, options);
106 
107  // GPUModule-specific stuff
108  buildGpuPassPipeline(pm, options);
109 
110  // Host post-GPUModule-specific stuff
111  buildHostPostPipeline(pm, options);
112 }
113 
116  "gpu-lower-to-nvvm-pipeline",
117  "The default pipeline lowers main dialects (arith, memref, scf, "
118  "vector, gpu, and nvgpu) to NVVM. It starts by lowering GPU code to the "
119  "specified compilation target (default is fatbin) then lowers the host "
120  "code.",
122 }
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:367
void addNestedPass(std::unique_ptr< Pass > pass)
Add the given pass to a nested pass manager for the given operation kind OpT.
Definition: PassManager.h:115
void registerGPUToNVVMPipeline()
Register all pipeleines 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 > createCSEPass()
Creates a pass to perform common sub expression elimination.
Definition: CSE.cpp:416
std::unique_ptr< Pass > createCanonicalizerPass()
Creates an instance of the Canonicalizer pass, configured with default settings (which can be overrid...
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...
Definition: PassRegistry.h:177
Options for the gpu to nvvm pipeline.
Definition: Passes.h:19