MLIR  19.0.0git
SparseTensorPipelines.cpp
Go to the documentation of this file.
1 //===- SparseTensorPipelines.cpp - Pipelines for sparse tensor code -------===//
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 
10 
12 #include "mlir/Conversion/Passes.h"
25 #include "mlir/Pass/PassManager.h"
26 #include "mlir/Transforms/Passes.h"
27 
28 //===----------------------------------------------------------------------===//
29 // Pipeline implementation.
30 //===----------------------------------------------------------------------===//
31 
33  const SparsifierOptions &options) {
34  // Rewrite named linalg ops into generic ops.
35  pm.addNestedPass<func::FuncOp>(createLinalgGeneralizeNamedOpsPass());
36 
37  // Sparsification and bufferization mini-pipeline.
40  options.testBufferizationAnalysisOnly),
41  options.sparsificationOptions(), options.createSparseDeallocs,
42  options.enableRuntimeLibrary, options.enableBufferInitialization,
43  options.vectorLength,
44  /*enableVLAVectorization=*/options.armSVE,
45  /*enableSIMDIndex32=*/options.force32BitVectorIndices,
46  options.enableGPULibgen));
47 
48  // Bail-early for test setup.
49  if (options.testBufferizationAnalysisOnly)
50  return;
51 
52  // Storage specifier lowering and bufferization wrap-up.
54  pm.addNestedPass<func::FuncOp>(createCanonicalizerPass());
55  pm.addNestedPass<func::FuncOp>(
57 
58  // GPU code generation.
59  const bool gpuCodegen = options.gpuTriple.hasValue();
60  if (gpuCodegen) {
62  pm.addNestedPass<gpu::GPUModuleOp>(createStripDebugInfoPass());
63  pm.addNestedPass<gpu::GPUModuleOp>(createConvertSCFToCFPass());
64  pm.addNestedPass<gpu::GPUModuleOp>(createConvertGpuOpsToNVVMOps());
65  }
66 
67  // Progressively lower to LLVM. Note that the convert-vector-to-llvm
68  // pass is repeated on purpose.
69  // TODO(springerm): Add sparse support to the BufferDeallocation pass and add
70  // it to this pipeline.
71  pm.addNestedPass<func::FuncOp>(createConvertLinalgToLoopsPass());
72  pm.addNestedPass<func::FuncOp>(createConvertVectorToSCFPass());
74  pm.addNestedPass<func::FuncOp>(createConvertSCFToCFPass());
77  pm.addPass(createConvertVectorToLLVMPass(options.lowerVectorToLLVMOptions()));
78  pm.addPass(createFinalizeMemRefToLLVMConversionPass());
80  pm.addNestedPass<func::FuncOp>(arith::createArithExpandOpsPass());
81  pm.addNestedPass<func::FuncOp>(createConvertMathToLLVMPass());
84  pm.addPass(createConvertVectorToLLVMPass(options.lowerVectorToLLVMOptions()));
85  pm.addPass(createConvertComplexToLLVMPass());
86  pm.addPass(createConvertVectorToLLVMPass(options.lowerVectorToLLVMOptions()));
87  pm.addPass(createConvertFuncToLLVMPass());
88 
89  // Finalize GPU code generation.
90  if (gpuCodegen) {
91  GpuNVVMAttachTargetOptions nvvmTargetOptions;
92  nvvmTargetOptions.triple = options.gpuTriple;
93  nvvmTargetOptions.chip = options.gpuChip;
94  nvvmTargetOptions.features = options.gpuFeatures;
95  pm.addPass(createGpuNVVMAttachTarget(nvvmTargetOptions));
96  pm.addPass(createGpuToLLVMConversionPass());
97  GpuModuleToBinaryPassOptions gpuModuleToBinaryPassOptions;
98  gpuModuleToBinaryPassOptions.compilationTarget = options.gpuFormat;
99  pm.addPass(createGpuModuleToBinaryPass(gpuModuleToBinaryPassOptions));
100  }
101 
102  // Ensure all casts are realized.
104 }
105 
106 //===----------------------------------------------------------------------===//
107 // Pipeline registration.
108 //===----------------------------------------------------------------------===//
109 
112  "sparsifier",
113  "The standard pipeline for taking sparsity-agnostic IR using the"
114  " sparse-tensor type, and lowering it to LLVM IR with concrete"
115  " representations and algorithms for sparse tensors.",
117 }
static llvm::ManagedStatic< PassManagerOptions > options
This class represents a pass manager that runs passes on either a specific operation type,...
Definition: PassManager.h:48
void addPass(std::unique_ptr< Pass > pass)
Add the given pass to this pass manager.
Definition: Pass.cpp:364
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:117
std::unique_ptr< OperationPass< func::FuncOp > > createFinalizingBufferizePass()
Creates a pass that finalizes a partial bufferization by removing remaining bufferization....
Definition: Bufferize.cpp:356
std::unique_ptr< Pass > createExpandStridedMetadataPass()
Creates an operation pass to expand some memref operation into easier to reason about operations.
std::unique_ptr< Pass > createExpandReallocPass(bool emitDeallocs=true)
Creates an operation pass to expand memref.realloc operations into their components.
void buildSparsifier(OpPassManager &pm, const SparsifierOptions &options)
Adds the "sparsifier" pipeline to the OpPassManager.
void registerSparseTensorPipelines()
Registers all pipelines for the sparse_tensor dialect.
std::unique_ptr< OperationPass< ModuleOp > > createConvertComplexToLibmPass()
Create a pass to convert Complex operations to libm calls.
std::unique_ptr< Pass > createSparseGPUCodegenPass()
bufferization::OneShotBufferizationOptions getBufferizationOptionsForSparsification(bool analysisOnly)
std::unique_ptr< Pass > createStripDebugInfoPass()
Creates a pass to strip debug information from a function.
std::unique_ptr< Pass > createSparsificationAndBufferizationPass()
std::unique_ptr< Pass > createConvertSCFToCFPass()
Creates a pass to convert SCF operations to CFG branch-based operation in the ControlFlow dialect.
std::unique_ptr< OperationPass< ModuleOp > > createConvertMathToLibmPass()
Create a pass to convert Math operations to libm calls.
Definition: MathToLibm.cpp:220
std::unique_ptr< Pass > createStorageSpecifierToLLVMPass()
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 > createConvertComplexToStandardPass()
Create a pass to convert Complex operations to the Standard dialect.
std::unique_ptr< Pass > createLowerAffinePass()
Lowers affine control flow operations (ForStmt, IfStmt and AffineApplyOp) to equivalent lower-level c...
PassPipelineRegistration provides a global initializer that registers a Pass pipeline builder routine...
Definition: PassRegistry.h:174
Options for the "sparsifier" pipeline.
Definition: Passes.h:30