MLIR  20.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 
35 #include "mlir/Pass/PassManager.h"
36 #include "mlir/Pass/PassOptions.h"
37 #include "mlir/Transforms/Passes.h"
38 
39 using namespace mlir;
40 
41 namespace {
42 
43 //===----------------------------------------------------------------------===//
44 // Common pipeline
45 //===----------------------------------------------------------------------===//
46 void buildCommonPassPipeline(
48  pm.addPass(createConvertNVGPUToNVVMPass());
52  pm.addPass(createConvertNVVMToLLVMPass());
53  pm.addPass(createConvertFuncToLLVMPass());
55 
56  GpuNVVMAttachTargetOptions nvvmTargetOptions;
57  nvvmTargetOptions.triple = options.cubinTriple;
58  nvvmTargetOptions.chip = options.cubinChip;
59  nvvmTargetOptions.features = options.cubinFeatures;
60  nvvmTargetOptions.optLevel = options.optLevel;
61  pm.addPass(createGpuNVVMAttachTarget(nvvmTargetOptions));
63  pm.addPass(createArithToLLVMConversionPass());
64  ConvertIndexToLLVMPassOptions convertIndexToLLVMPassOpt;
65  convertIndexToLLVMPassOpt.indexBitwidth = options.indexBitWidth;
66  pm.addPass(createConvertIndexToLLVMPass(convertIndexToLLVMPassOpt));
68  pm.addPass(createCSEPass());
69 }
70 
71 //===----------------------------------------------------------------------===//
72 // GPUModule-specific stuff.
73 //===----------------------------------------------------------------------===//
74 void buildGpuPassPipeline(OpPassManager &pm,
76  pm.addNestedPass<gpu::GPUModuleOp>(createStripDebugInfoPass());
77  ConvertGpuOpsToNVVMOpsOptions opt;
78  opt.useBarePtrCallConv = options.kernelUseBarePtrCallConv;
79  opt.indexBitwidth = options.indexBitWidth;
80  pm.addNestedPass<gpu::GPUModuleOp>(createConvertGpuOpsToNVVMOps(opt));
81  pm.addNestedPass<gpu::GPUModuleOp>(createCanonicalizerPass());
82  pm.addNestedPass<gpu::GPUModuleOp>(createCSEPass());
83  pm.addNestedPass<gpu::GPUModuleOp>(createReconcileUnrealizedCastsPass());
84 }
85 
86 //===----------------------------------------------------------------------===//
87 // Host Post-GPU pipeline
88 //===----------------------------------------------------------------------===//
89 void buildHostPostPipeline(OpPassManager &pm,
91  GpuToLLVMConversionPassOptions opt;
92  opt.hostBarePtrCallConv = options.hostUseBarePtrCallConv;
93  opt.kernelBarePtrCallConv = options.kernelUseBarePtrCallConv;
94  pm.addPass(createGpuToLLVMConversionPass(opt));
95 
96  GpuModuleToBinaryPassOptions gpuModuleToBinaryPassOptions;
97  gpuModuleToBinaryPassOptions.compilationTarget = options.cubinFormat;
98  pm.addPass(createGpuModuleToBinaryPass(gpuModuleToBinaryPassOptions));
99  pm.addPass(createConvertMathToLLVMPass());
101  pm.addPass(createCSEPass());
103 }
104 
105 } // namespace
106 
109  // Common pipelines
110  buildCommonPassPipeline(pm, options);
111 
112  // GPUModule-specific stuff
113  buildGpuPassPipeline(pm, options);
114 
115  // Host post-GPUModule-specific stuff
116  buildHostPostPipeline(pm, options);
117 }
118 
121  "gpu-lower-to-nvvm-pipeline",
122  "The default pipeline lowers main dialects (arith, memref, scf, "
123  "vector, gpu, and nvgpu) to NVVM. It starts by lowering GPU code to the "
124  "specified compilation target (default is fatbin) then lowers the host "
125  "code.",
127 }
static llvm::ManagedStatic< PassManagerOptions > options
This class represents a pass manager that runs passes on either a specific operation type,...
Definition: PassManager.h:47
void addPass(std::unique_ptr< Pass > pass)
Add the given pass to this pass manager.
Definition: Pass.cpp:363
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:116
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.
std::unique_ptr< Pass > createExpandStridedMetadataPass()
Creates an operation pass to expand some memref operation into easier to reason about operations.
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 > createStripDebugInfoPass()
Creates a pass to strip debug information from a function.
std::unique_ptr< Pass > createConvertSCFToCFPass()
Creates a pass to convert SCF operations to CFG branch-based operation in the ControlFlow dialect.
std::unique_ptr< Pass > createCanonicalizerPass()
Creates an instance of the Canonicalizer pass, configured with default settings (which can be overrid...
std::unique_ptr< Pass > createReconcileUnrealizedCastsPass()
Creates a pass that eliminates noop unrealized_conversion_cast operation sequences.
std::unique_ptr< Pass > createConvertVectorToSCFPass(const VectorTransferToSCFOptions &options=VectorTransferToSCFOptions())
Create a pass to convert a subset of vector ops to SCF.
std::unique_ptr< Pass > createLowerAffinePass()
Lowers affine control flow operations (ForStmt, IfStmt and AffineApplyOp) to equivalent lower-level c...
std::unique_ptr< OperationPass< ModuleOp > > createGpuKernelOutliningPass(StringRef dataLayoutStr=StringRef())
Replaces gpu.launch with gpu.launch_func by moving the region into a separate kernel function.
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