diff --git a/mlir/include/mlir/Conversion/AMDGPUToROCDL/AMDGPUToROCDL.h b/mlir/include/mlir/Conversion/AMDGPUToROCDL/AMDGPUToROCDL.h --- a/mlir/include/mlir/Conversion/AMDGPUToROCDL/AMDGPUToROCDL.h +++ b/mlir/include/mlir/Conversion/AMDGPUToROCDL/AMDGPUToROCDL.h @@ -17,12 +17,17 @@ class RewritePatternSet; class Pass; +struct ConvertAMDGPUToROCDLBaseOptions; + void populateAMDGPUToROCDLConversionPatterns(LLVMTypeConverter &converter, RewritePatternSet &patterns, amdgpu::Chipset chipset); std::unique_ptr createConvertAMDGPUToROCDLPass(); +std::unique_ptr +createConvertAMDGPUToROCDLPass(const ConvertAMDGPUToROCDLBaseOptions &options); + } // namespace mlir #endif // MLIR_CONVERSION_AMDGPUTOROCDL_AMDGPUTOROCDL_H_ diff --git a/mlir/include/mlir/Conversion/ArithmeticToLLVM/ArithmeticToLLVM.h b/mlir/include/mlir/Conversion/ArithmeticToLLVM/ArithmeticToLLVM.h --- a/mlir/include/mlir/Conversion/ArithmeticToLLVM/ArithmeticToLLVM.h +++ b/mlir/include/mlir/Conversion/ArithmeticToLLVM/ArithmeticToLLVM.h @@ -17,11 +17,16 @@ class RewritePatternSet; class Pass; +struct ConvertArithmeticToLLVMBaseOptions; + namespace arith { void populateArithmeticToLLVMConversionPatterns(LLVMTypeConverter &converter, RewritePatternSet &patterns); std::unique_ptr createConvertArithmeticToLLVMPass(); + +std::unique_ptr createConvertArithmeticToLLVMPass( + const ConvertArithmeticToLLVMBaseOptions &options); } // namespace arith } // namespace mlir diff --git a/mlir/include/mlir/Conversion/ArithmeticToSPIRV/ArithmeticToSPIRV.h b/mlir/include/mlir/Conversion/ArithmeticToSPIRV/ArithmeticToSPIRV.h --- a/mlir/include/mlir/Conversion/ArithmeticToSPIRV/ArithmeticToSPIRV.h +++ b/mlir/include/mlir/Conversion/ArithmeticToSPIRV/ArithmeticToSPIRV.h @@ -18,11 +18,16 @@ class RewritePatternSet; class Pass; +struct ConvertArithmeticToSPIRVBaseOptions; + namespace arith { void populateArithmeticToSPIRVPatterns(SPIRVTypeConverter &typeConverter, RewritePatternSet &patterns); std::unique_ptr> createConvertArithmeticToSPIRVPass(); + +std::unique_ptr> createConvertArithmeticToSPIRVPass( + const ConvertArithmeticToSPIRVBaseOptions &options); } // namespace arith } // namespace mlir diff --git a/mlir/include/mlir/Conversion/ControlFlowToLLVM/ControlFlowToLLVM.h b/mlir/include/mlir/Conversion/ControlFlowToLLVM/ControlFlowToLLVM.h --- a/mlir/include/mlir/Conversion/ControlFlowToLLVM/ControlFlowToLLVM.h +++ b/mlir/include/mlir/Conversion/ControlFlowToLLVM/ControlFlowToLLVM.h @@ -20,6 +20,8 @@ class RewritePatternSet; class Pass; +struct ConvertControlFlowToLLVMBaseOptions; + namespace cf { /// Collect the patterns to convert from the ControlFlow dialect to LLVM. The /// conversion patterns capture the LLVMTypeConverter by reference meaning the @@ -29,6 +31,10 @@ /// Creates a pass to convert the ControlFlow dialect into the LLVMIR dialect. std::unique_ptr createConvertControlFlowToLLVMPass(); + +/// Creates a pass to convert the ControlFlow dialect into the LLVMIR dialect. +std::unique_ptr createConvertControlFlowToLLVMPass( + const ConvertControlFlowToLLVMBaseOptions &options); } // namespace cf } // namespace mlir diff --git a/mlir/include/mlir/Conversion/ControlFlowToSPIRV/ControlFlowToSPIRVPass.h b/mlir/include/mlir/Conversion/ControlFlowToSPIRV/ControlFlowToSPIRVPass.h --- a/mlir/include/mlir/Conversion/ControlFlowToSPIRV/ControlFlowToSPIRVPass.h +++ b/mlir/include/mlir/Conversion/ControlFlowToSPIRV/ControlFlowToSPIRVPass.h @@ -18,9 +18,15 @@ namespace mlir { class ModuleOp; +struct ConvertControlFlowToSPIRVBaseOptions; + /// Creates a pass to convert ControlFlow ops to SPIR-V ops. std::unique_ptr> createConvertControlFlowToSPIRVPass(); +/// Creates a pass to convert ControlFlow ops to SPIR-V ops. +std::unique_ptr> createConvertControlFlowToSPIRVPass( + const ConvertControlFlowToSPIRVBaseOptions &options); + } // namespace mlir #endif // MLIR_CONVERSION_CONTROLFLOWTOSPIRV_CONTROLFLOWTOSPIRVPASS_H diff --git a/mlir/include/mlir/Conversion/FuncToLLVM/ConvertFuncToLLVMPass.h b/mlir/include/mlir/Conversion/FuncToLLVM/ConvertFuncToLLVMPass.h --- a/mlir/include/mlir/Conversion/FuncToLLVM/ConvertFuncToLLVMPass.h +++ b/mlir/include/mlir/Conversion/FuncToLLVM/ConvertFuncToLLVMPass.h @@ -18,10 +18,13 @@ class OperationPass; class Pass; +struct ConvertFuncToLLVMBaseOptions; + /// Creates a pass to convert the Func dialect into the LLVMIR dialect. std::unique_ptr> createConvertFuncToLLVMPass(); + std::unique_ptr> -createConvertFuncToLLVMPass(const LowerToLLVMOptions &options); +createConvertFuncToLLVMPass(const ConvertFuncToLLVMBaseOptions &options); } // namespace mlir diff --git a/mlir/include/mlir/Conversion/FuncToSPIRV/FuncToSPIRVPass.h b/mlir/include/mlir/Conversion/FuncToSPIRV/FuncToSPIRVPass.h --- a/mlir/include/mlir/Conversion/FuncToSPIRV/FuncToSPIRVPass.h +++ b/mlir/include/mlir/Conversion/FuncToSPIRV/FuncToSPIRVPass.h @@ -18,9 +18,15 @@ namespace mlir { class ModuleOp; +struct ConvertFuncToSPIRVBaseOptions; + /// Creates a pass to convert Func ops to SPIR-V ops. std::unique_ptr> createConvertFuncToSPIRVPass(); +/// Creates a pass to convert Func ops to SPIR-V ops. +std::unique_ptr> +createConvertFuncToSPIRVPass(const ConvertFuncToSPIRVBaseOptions &options); + } // namespace mlir #endif // MLIR_CONVERSION_FUNCTOSPIRV_FUNCTOSPIRVPASS_H diff --git a/mlir/include/mlir/Conversion/GPUCommon/GPUCommonPass.h b/mlir/include/mlir/Conversion/GPUCommon/GPUCommonPass.h --- a/mlir/include/mlir/Conversion/GPUCommon/GPUCommonPass.h +++ b/mlir/include/mlir/Conversion/GPUCommon/GPUCommonPass.h @@ -30,6 +30,8 @@ template class OperationPass; +struct GpuToLLVMConversionPassBaseOptions; + namespace gpu { class GPUModuleOp; } // namespace gpu @@ -50,8 +52,10 @@ /// This pass does not generate code to call GPU runtime APIs directly but /// instead uses a small wrapper library that exports a stable and conveniently /// typed ABI on top of GPU runtimes such as CUDA or ROCm (HIP). -std::unique_ptr> -createGpuToLLVMConversionPass(bool kernelBarePtrCallConv = false); +std::unique_ptr> createGpuToLLVMConversionPass(); + +std::unique_ptr> createGpuToLLVMConversionPass( + const GpuToLLVMConversionPassBaseOptions &options); /// Collect a set of patterns to convert from the GPU dialect to LLVM and /// populate converter for gpu types. diff --git a/mlir/include/mlir/Conversion/GPUToNVVM/GPUToNVVMPass.h b/mlir/include/mlir/Conversion/GPUToNVVM/GPUToNVVMPass.h --- a/mlir/include/mlir/Conversion/GPUToNVVM/GPUToNVVMPass.h +++ b/mlir/include/mlir/Conversion/GPUToNVVM/GPUToNVVMPass.h @@ -20,6 +20,8 @@ template class OperationPass; +struct ConvertGpuOpsToNVVMOpsBaseOptions; + namespace gpu { class GPUModuleOp; class MMAMatrixType; @@ -38,11 +40,13 @@ void populateGpuWMMAToNVVMConversionPatterns(LLVMTypeConverter &converter, RewritePatternSet &patterns); -/// Creates a pass that lowers GPU dialect operations to NVVM counterparts. The -/// index bitwidth used for the lowering of the device side index computations -/// is configurable. +/// Creates a pass that lowers GPU dialect operations to NVVM counterparts. +std::unique_ptr> +createLowerGpuOpsToNVVMOpsPass(); + +/// Creates a pass that lowers GPU dialect operations to NVVM counterparts. std::unique_ptr> createLowerGpuOpsToNVVMOpsPass( - unsigned indexBitwidth = kDeriveIndexBitwidthFromDataLayout); + const ConvertGpuOpsToNVVMOpsBaseOptions &options); } // namespace mlir diff --git a/mlir/include/mlir/Conversion/GPUToROCDL/GPUToROCDLPass.h b/mlir/include/mlir/Conversion/GPUToROCDL/GPUToROCDLPass.h --- a/mlir/include/mlir/Conversion/GPUToROCDL/GPUToROCDLPass.h +++ b/mlir/include/mlir/Conversion/GPUToROCDL/GPUToROCDLPass.h @@ -20,6 +20,8 @@ template class OperationPass; +struct ConvertGpuOpsToROCDLOpsBaseOptions; + namespace gpu { class GPUModuleOp; } // namespace gpu @@ -34,15 +36,14 @@ /// Configure target to convert from the GPU dialect to ROCDL. void configureGpuToROCDLConversionLegality(ConversionTarget &target); -/// Creates a pass that lowers GPU dialect operations to ROCDL counterparts. The -/// index bitwidth used for the lowering of the device side index computations -/// is configurable. +/// Creates a pass that lowers GPU dialect operations to ROCDL counterparts. +std::unique_ptr> +createLowerGpuOpsToROCDLOpsPass(); + +/// Creates a pass that lowers GPU dialect operations to ROCDL counterparts. std::unique_ptr> createLowerGpuOpsToROCDLOpsPass( - const std::string &chipset = "gfx900", - unsigned indexBitwidth = kDeriveIndexBitwidthFromDataLayout, - bool useBarePtrCallConv = false, - gpu::amd::Runtime runtime = gpu::amd::Runtime::Unknown); + const ConvertGpuOpsToROCDLOpsBaseOptions &options); } // namespace mlir diff --git a/mlir/include/mlir/Conversion/GPUToSPIRV/GPUToSPIRVPass.h b/mlir/include/mlir/Conversion/GPUToSPIRV/GPUToSPIRVPass.h --- a/mlir/include/mlir/Conversion/GPUToSPIRV/GPUToSPIRVPass.h +++ b/mlir/include/mlir/Conversion/GPUToSPIRV/GPUToSPIRVPass.h @@ -21,12 +21,20 @@ template class OperationPass; +struct ConvertGPUToSPIRVBaseOptions; + +/// Creates a pass to convert GPU kernel ops to corresponding SPIR-V ops. For a +/// gpu.func to be converted, it should have a spv.entry_point_abi attribute. +/// If the `mapMemorySpace` option is true, performs MemRef memory space to +/// SPIR-V mapping according to default Vulkan rules first. +std::unique_ptr> createConvertGPUToSPIRVPass(); + /// Creates a pass to convert GPU kernel ops to corresponding SPIR-V ops. For a /// gpu.func to be converted, it should have a spv.entry_point_abi attribute. -/// If `mapMemorySpace` is true, performs MemRef memory space to SPIR-V mapping -/// according to default Vulkan rules first. +/// If the `mapMemorySpace` option is true, performs MemRef memory space to +/// SPIR-V mapping according to default Vulkan rules first. std::unique_ptr> -createConvertGPUToSPIRVPass(bool mapMemorySpace = false); +createConvertGPUToSPIRVPass(const ConvertGPUToSPIRVBaseOptions &options); } // namespace mlir #endif // MLIR_CONVERSION_GPUTOSPIRV_GPUTOSPIRVPASS_H diff --git a/mlir/include/mlir/Conversion/MemRefToLLVM/MemRefToLLVM.h b/mlir/include/mlir/Conversion/MemRefToLLVM/MemRefToLLVM.h --- a/mlir/include/mlir/Conversion/MemRefToLLVM/MemRefToLLVM.h +++ b/mlir/include/mlir/Conversion/MemRefToLLVM/MemRefToLLVM.h @@ -16,12 +16,18 @@ class LLVMTypeConverter; class RewritePatternSet; +struct ConvertMemRefToLLVMBaseOptions; + /// Collect a set of patterns to convert memory-related operations from the /// MemRef dialect to the LLVM dialect. void populateMemRefToLLVMConversionPatterns(LLVMTypeConverter &converter, RewritePatternSet &patterns); std::unique_ptr createMemRefToLLVMPass(); + +std::unique_ptr +createMemRefToLLVMPass(const ConvertMemRefToLLVMBaseOptions &options); + } // namespace mlir #endif // MLIR_CONVERSION_MEMREFTOLLVM_MEMREFTOLLVM_H diff --git a/mlir/include/mlir/Conversion/MemRefToSPIRV/MemRefToSPIRVPass.h b/mlir/include/mlir/Conversion/MemRefToSPIRV/MemRefToSPIRVPass.h --- a/mlir/include/mlir/Conversion/MemRefToSPIRV/MemRefToSPIRVPass.h +++ b/mlir/include/mlir/Conversion/MemRefToSPIRV/MemRefToSPIRVPass.h @@ -19,6 +19,8 @@ namespace mlir { class ModuleOp; +struct ConvertMemRefToSPIRVBaseOptions; + /// Creates a pass to map numeric MemRef memory spaces to symbolic SPIR-V /// storage classes. The mapping is read from the command-line option. std::unique_ptr> createMapMemRefStorageClassPass(); @@ -26,6 +28,10 @@ /// Creates a pass to convert MemRef ops to SPIR-V ops. std::unique_ptr> createConvertMemRefToSPIRVPass(); +/// Creates a pass to convert MemRef ops to SPIR-V ops. +std::unique_ptr> +createConvertMemRefToSPIRVPass(const ConvertMemRefToSPIRVBaseOptions &options); + } // namespace mlir #endif // MLIR_CONVERSION_MEMREFTOSPIRV_MEMREFTOSPIRVPASS_H diff --git a/mlir/include/mlir/Conversion/Passes.h b/mlir/include/mlir/Conversion/Passes.h --- a/mlir/include/mlir/Conversion/Passes.h +++ b/mlir/include/mlir/Conversion/Passes.h @@ -62,6 +62,10 @@ namespace mlir { +/// Generate the option structures to configure the conversion passes. +#define GEN_PASS_OPTIONS +#include "mlir/Conversion/Passes.h.inc" + /// Generate the code for registering conversion passes. #define GEN_PASS_REGISTRATION #include "mlir/Conversion/Passes.h.inc" diff --git a/mlir/include/mlir/Conversion/Passes.td b/mlir/include/mlir/Conversion/Passes.td --- a/mlir/include/mlir/Conversion/Passes.td +++ b/mlir/include/mlir/Conversion/Passes.td @@ -331,6 +331,10 @@ let summary = "Convert GPU dialect to LLVM dialect with GPU runtime calls"; let constructor = "mlir::createGpuToLLVMConversionPass()"; let dependentDialects = ["LLVM::LLVMDialect"]; + let options = [ + Option<"kernelBarePtrCallConv", "kernel-bare-ptr-call-conv", "bool", + /*default=*/"false", "Use bare pointer calling convention">, + ]; } def LowerHostCodeToLLVM : Pass<"lower-host-to-llvm", "ModuleOp"> { @@ -408,6 +412,12 @@ }]; let constructor = "mlir::createConvertGPUToSPIRVPass()"; let dependentDialects = ["spirv::SPIRVDialect"]; + let options = [ + Option<"mapMemorySpace", "map-memory-space", + "bool", /*default=*/"false", + "Performs MemRef memory space to SPIR-V mapping according to default" + " Vulkan rules first"> + ]; } //===----------------------------------------------------------------------===// diff --git a/mlir/include/mlir/Conversion/SCFToGPU/SCFToGPUPass.h b/mlir/include/mlir/Conversion/SCFToGPU/SCFToGPUPass.h --- a/mlir/include/mlir/Conversion/SCFToGPU/SCFToGPUPass.h +++ b/mlir/include/mlir/Conversion/SCFToGPU/SCFToGPUPass.h @@ -18,6 +18,8 @@ class InterfacePass; class Pass; +struct ConvertAffineForToGPUBaseOptions; + /// Create a pass that converts loop nests into GPU kernels. It considers /// top-level affine.for operations as roots of loop nests and converts them to /// the gpu.launch operations if possible. @@ -26,10 +28,11 @@ /// parallelization is performed, it is under the responsibility of the caller /// to strip-mine the loops and to perform the dependence analysis before /// calling the conversion. -std::unique_ptr> -createAffineForToGPUPass(unsigned numBlockDims, unsigned numThreadDims); std::unique_ptr> createAffineForToGPUPass(); +std::unique_ptr> +createAffineForToGPUPass(const ConvertAffineForToGPUBaseOptions &options); + /// Creates a pass that converts scf.parallel operations into a gpu.launch /// operation. The mapping of loop dimensions to launch dimensions is derived /// from mapping attributes. See ParallelToGpuLaunchLowering::matchAndRewrite diff --git a/mlir/include/mlir/Conversion/TensorToSPIRV/TensorToSPIRVPass.h b/mlir/include/mlir/Conversion/TensorToSPIRV/TensorToSPIRVPass.h --- a/mlir/include/mlir/Conversion/TensorToSPIRV/TensorToSPIRVPass.h +++ b/mlir/include/mlir/Conversion/TensorToSPIRV/TensorToSPIRVPass.h @@ -18,9 +18,15 @@ namespace mlir { class ModuleOp; +struct ConvertTensorToSPIRVBaseOptions; + /// Creates a pass to convert Tensor ops to SPIR-V ops. std::unique_ptr> createConvertTensorToSPIRVPass(); +/// Creates a pass to convert Tensor ops to SPIR-V ops. +std::unique_ptr> +createConvertTensorToSPIRVPass(const ConvertTensorToSPIRVBaseOptions &options); + } // namespace mlir #endif // MLIR_CONVERSION_TENSORTOSPIRV_TENSORTOSPIRVPASS_H diff --git a/mlir/include/mlir/Conversion/TosaToArith/TosaToArith.h b/mlir/include/mlir/Conversion/TosaToArith/TosaToArith.h --- a/mlir/include/mlir/Conversion/TosaToArith/TosaToArith.h +++ b/mlir/include/mlir/Conversion/TosaToArith/TosaToArith.h @@ -16,10 +16,14 @@ #include "mlir/Pass/Pass.h" namespace mlir { +struct TosaToArithBaseOptions; + namespace tosa { std::unique_ptr createTosaToArith(); +std::unique_ptr createTosaToArith(const TosaToArithBaseOptions &options); + void populateTosaToArithConversionPatterns(RewritePatternSet *patterns); void populateTosaRescaleToArithConversionPatterns(RewritePatternSet *patterns, diff --git a/mlir/include/mlir/Conversion/VectorToGPU/VectorToGPU.h b/mlir/include/mlir/Conversion/VectorToGPU/VectorToGPU.h --- a/mlir/include/mlir/Conversion/VectorToGPU/VectorToGPU.h +++ b/mlir/include/mlir/Conversion/VectorToGPU/VectorToGPU.h @@ -16,6 +16,8 @@ class Pass; class RewritePatternSet; +struct ConvertVectorToGPUBaseOptions; + /// Patterns to transform vector ops into a canonical form to convert to MMA /// matrix operations. If `useNvGpu` is true, then the patterns will populated /// will prepare for conversion to `nvgpu` mma operations rather than the `gpu` @@ -35,7 +37,11 @@ LogicalResult convertVectorToNVVMCompatibleMMASync(Operation *rootOp); /// Convert from vector to GPU ops. -std::unique_ptr createConvertVectorToGPUPass(bool useNvGpu = false); +std::unique_ptr createConvertVectorToGPUPass(); + +/// Convert from vector to GPU ops. +std::unique_ptr +createConvertVectorToGPUPass(const ConvertVectorToGPUBaseOptions &options); } // namespace mlir diff --git a/mlir/include/mlir/Conversion/VectorToLLVM/ConvertVectorToLLVM.h b/mlir/include/mlir/Conversion/VectorToLLVM/ConvertVectorToLLVM.h --- a/mlir/include/mlir/Conversion/VectorToLLVM/ConvertVectorToLLVM.h +++ b/mlir/include/mlir/Conversion/VectorToLLVM/ConvertVectorToLLVM.h @@ -16,45 +16,7 @@ template class OperationPass; -/// Options to control Vector to LLVM lowering. -/// -/// This should kept in sync with VectorToLLVM options defined for the -/// ConvertVectorToLLVM pass in include/mlir/Conversion/Passes.td -struct LowerVectorToLLVMOptions { - LowerVectorToLLVMOptions() {} - - LowerVectorToLLVMOptions &enableReassociateFPReductions(bool b = true) { - reassociateFPReductions = b; - return *this; - } - LowerVectorToLLVMOptions &enableIndexOptimizations(bool b = true) { - force32BitVectorIndices = b; - return *this; - } - LowerVectorToLLVMOptions &enableArmNeon(bool b = true) { - armNeon = b; - return *this; - } - LowerVectorToLLVMOptions &enableArmSVE(bool b = true) { - armSVE = b; - return *this; - } - LowerVectorToLLVMOptions &enableAMX(bool b = true) { - amx = b; - return *this; - } - LowerVectorToLLVMOptions &enableX86Vector(bool b = true) { - x86Vector = b; - return *this; - } - - bool reassociateFPReductions{false}; - bool force32BitVectorIndices{true}; - bool armNeon{false}; - bool armSVE{false}; - bool amx{false}; - bool x86Vector{false}; -}; +struct ConvertVectorToLLVMBaseOptions; /// Collect a set of patterns to convert from Vector contractions to LLVM Matrix /// Intrinsics. To lower to assembly, the LLVM flag -lower-matrix-intrinsics @@ -68,8 +30,10 @@ bool reassociateFPReductions = false, bool force32BitVectorIndices = false); /// Create a pass to convert vector operations to the LLVMIR dialect. -std::unique_ptr> createConvertVectorToLLVMPass( - const LowerVectorToLLVMOptions &options = LowerVectorToLLVMOptions()); +std::unique_ptr> createConvertVectorToLLVMPass(); + +std::unique_ptr> +createConvertVectorToLLVMPass(const ConvertVectorToLLVMBaseOptions &options); } // namespace mlir diff --git a/mlir/include/mlir/Dialect/SparseTensor/Pipelines/Passes.h b/mlir/include/mlir/Dialect/SparseTensor/Pipelines/Passes.h --- a/mlir/include/mlir/Dialect/SparseTensor/Pipelines/Passes.h +++ b/mlir/include/mlir/Dialect/SparseTensor/Pipelines/Passes.h @@ -95,18 +95,6 @@ desc("Enables the use of X86Vector dialect while lowering the vector " "dialect."), init(false)}; - - /// Projects out the options for `createConvertVectorToLLVMPass`. - LowerVectorToLLVMOptions lowerVectorToLLVMOptions() const { - LowerVectorToLLVMOptions opts{}; - opts.enableReassociateFPReductions(reassociateFPReductions); - opts.enableIndexOptimizations(indexOptimizations); - opts.enableArmNeon(armNeon); - opts.enableArmSVE(armSVE); - opts.enableAMX(amx); - opts.enableX86Vector(x86Vector); - return opts; - } }; //===----------------------------------------------------------------------===// diff --git a/mlir/include/mlir/Dialect/Tosa/Transforms/PassDetail.h b/mlir/include/mlir/Dialect/Tosa/Transforms/PassDetail.h --- a/mlir/include/mlir/Dialect/Tosa/Transforms/PassDetail.h +++ b/mlir/include/mlir/Dialect/Tosa/Transforms/PassDetail.h @@ -16,6 +16,7 @@ namespace mlir { +#define GEN_PASS_OPTIONS #define GEN_PASS_CLASSES #include "mlir/Dialect/Tosa/Transforms/Passes.h.inc" diff --git a/mlir/include/mlir/Reducer/PassDetail.h b/mlir/include/mlir/Reducer/PassDetail.h --- a/mlir/include/mlir/Reducer/PassDetail.h +++ b/mlir/include/mlir/Reducer/PassDetail.h @@ -14,6 +14,7 @@ namespace mlir { +#define GEN_PASS_OPTIONS #define GEN_PASS_CLASSES #include "mlir/Reducer/Passes.h.inc" diff --git a/mlir/lib/Conversion/AMDGPUToROCDL/AMDGPUToROCDL.cpp b/mlir/lib/Conversion/AMDGPUToROCDL/AMDGPUToROCDL.cpp --- a/mlir/lib/Conversion/AMDGPUToROCDL/AMDGPUToROCDL.cpp +++ b/mlir/lib/Conversion/AMDGPUToROCDL/AMDGPUToROCDL.cpp @@ -272,6 +272,8 @@ : public ConvertAMDGPUToROCDLBase { ConvertAMDGPUToROCDLPass() = default; + ConvertAMDGPUToROCDLPass(const ConvertAMDGPUToROCDLBaseOptions &options) : ConvertAMDGPUToROCDLBase(options) {} + void runOnOperation() override { MLIRContext *ctx = &getContext(); FailureOr maybeChipset = Chipset::parse(chipset); @@ -307,3 +309,7 @@ std::unique_ptr mlir::createConvertAMDGPUToROCDLPass() { return std::make_unique(); } + +std::unique_ptr mlir::createConvertAMDGPUToROCDLPass(const ConvertAMDGPUToROCDLBaseOptions &options) { + return std::make_unique(options); +} diff --git a/mlir/lib/Conversion/ArithmeticToLLVM/ArithmeticToLLVM.cpp b/mlir/lib/Conversion/ArithmeticToLLVM/ArithmeticToLLVM.cpp --- a/mlir/lib/Conversion/ArithmeticToLLVM/ArithmeticToLLVM.cpp +++ b/mlir/lib/Conversion/ArithmeticToLLVM/ArithmeticToLLVM.cpp @@ -261,6 +261,8 @@ : public ConvertArithmeticToLLVMBase { ConvertArithmeticToLLVMPass() = default; + ConvertArithmeticToLLVMPass(const ConvertArithmeticToLLVMBaseOptions &options) : ConvertArithmeticToLLVMBase(options) {} + void runOnOperation() override { LLVMConversionTarget target(getContext()); RewritePatternSet patterns(&getContext()); @@ -329,3 +331,7 @@ std::unique_ptr mlir::arith::createConvertArithmeticToLLVMPass() { return std::make_unique(); } + +std::unique_ptr mlir::arith::createConvertArithmeticToLLVMPass(const ConvertArithmeticToLLVMBaseOptions &options) { + return std::make_unique(options); +} \ No newline at end of file diff --git a/mlir/lib/Conversion/ArithmeticToSPIRV/ArithmeticToSPIRV.cpp b/mlir/lib/Conversion/ArithmeticToSPIRV/ArithmeticToSPIRV.cpp --- a/mlir/lib/Conversion/ArithmeticToSPIRV/ArithmeticToSPIRV.cpp +++ b/mlir/lib/Conversion/ArithmeticToSPIRV/ArithmeticToSPIRV.cpp @@ -911,6 +911,10 @@ namespace { struct ConvertArithmeticToSPIRVPass : public ConvertArithmeticToSPIRVBase { + ConvertArithmeticToSPIRVPass() = default; + + ConvertArithmeticToSPIRVPass(const ConvertArithmeticToSPIRVBaseOptions &options) : ConvertArithmeticToSPIRVBase(options) {} + void runOnOperation() override { Operation *op = getOperation(); auto targetAttr = spirv::lookupTargetEnvOrDefault(op); @@ -944,3 +948,7 @@ mlir::arith::createConvertArithmeticToSPIRVPass() { return std::make_unique(); } + +std::unique_ptr> mlir::arith::createConvertArithmeticToSPIRVPass(const ConvertArithmeticToSPIRVBaseOptions &options) { + return std::make_unique(options); +} diff --git a/mlir/lib/Conversion/ControlFlowToLLVM/ControlFlowToLLVM.cpp b/mlir/lib/Conversion/ControlFlowToLLVM/ControlFlowToLLVM.cpp --- a/mlir/lib/Conversion/ControlFlowToLLVM/ControlFlowToLLVM.cpp +++ b/mlir/lib/Conversion/ControlFlowToLLVM/ControlFlowToLLVM.cpp @@ -199,6 +199,9 @@ : public ConvertControlFlowToLLVMBase { ConvertControlFlowToLLVM() = default; + ConvertControlFlowToLLVM(const ConvertControlFlowToLLVMBaseOptions &options) + : ConvertControlFlowToLLVMBase(options) {} + /// Run the dialect converter on the module. void runOnOperation() override { LLVMConversionTarget target(getContext()); @@ -221,3 +224,8 @@ std::unique_ptr mlir::cf::createConvertControlFlowToLLVMPass() { return std::make_unique(); } + +std::unique_ptr mlir::cf::createConvertControlFlowToLLVMPass( + const ConvertControlFlowToLLVMBaseOptions &options) { + return std::make_unique(options); +} diff --git a/mlir/lib/Conversion/ControlFlowToSPIRV/ControlFlowToSPIRVPass.cpp b/mlir/lib/Conversion/ControlFlowToSPIRV/ControlFlowToSPIRVPass.cpp --- a/mlir/lib/Conversion/ControlFlowToSPIRV/ControlFlowToSPIRVPass.cpp +++ b/mlir/lib/Conversion/ControlFlowToSPIRV/ControlFlowToSPIRVPass.cpp @@ -20,8 +20,14 @@ namespace { /// A pass converting MLIR ControlFlow operations into the SPIR-V dialect. -class ConvertControlFlowToSPIRVPass +struct ConvertControlFlowToSPIRVPass : public ConvertControlFlowToSPIRVBase { + ConvertControlFlowToSPIRVPass() = default; + + ConvertControlFlowToSPIRVPass( + const ConvertControlFlowToSPIRVBaseOptions &options) + : ConvertControlFlowToSPIRVBase(options) {} + void runOnOperation() override; }; } // namespace @@ -48,3 +54,8 @@ std::unique_ptr> mlir::createConvertControlFlowToSPIRVPass() { return std::make_unique(); } + +std::unique_ptr> mlir::createConvertControlFlowToSPIRVPass( + const ConvertControlFlowToSPIRVBaseOptions &options) { + return std::make_unique(options); +} diff --git a/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp b/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp --- a/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp +++ b/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp @@ -665,13 +665,8 @@ struct ConvertFuncToLLVMPass : public ConvertFuncToLLVMBase { ConvertFuncToLLVMPass() = default; - ConvertFuncToLLVMPass(bool useBarePtrCallConv, unsigned indexBitwidth, - bool useAlignedAlloc, - const llvm::DataLayout &dataLayout) { - this->useBarePtrCallConv = useBarePtrCallConv; - this->indexBitwidth = indexBitwidth; - this->dataLayout = dataLayout.getStringRepresentation(); - } + + ConvertFuncToLLVMPass(const ConvertFuncToLLVMBaseOptions &options) : ConvertFuncToLLVMBase(options) {} /// Run the dialect converter on the module. void runOnOperation() override { @@ -718,15 +713,6 @@ } std::unique_ptr> -mlir::createConvertFuncToLLVMPass(const LowerToLLVMOptions &options) { - auto allocLowering = options.allocLowering; - // There is no way to provide additional patterns for pass, so - // AllocLowering::None will always fail. - assert(allocLowering != LowerToLLVMOptions::AllocLowering::None && - "ConvertFuncToLLVMPass doesn't support AllocLowering::None"); - bool useAlignedAlloc = - (allocLowering == LowerToLLVMOptions::AllocLowering::AlignedAlloc); - return std::make_unique( - options.useBarePtrCallConv, options.getIndexBitwidth(), useAlignedAlloc, - options.dataLayout); +mlir::createConvertFuncToLLVMPass(const ConvertFuncToLLVMBaseOptions &options) { + return std::make_unique(options); } diff --git a/mlir/lib/Conversion/FuncToSPIRV/FuncToSPIRVPass.cpp b/mlir/lib/Conversion/FuncToSPIRV/FuncToSPIRVPass.cpp --- a/mlir/lib/Conversion/FuncToSPIRV/FuncToSPIRVPass.cpp +++ b/mlir/lib/Conversion/FuncToSPIRV/FuncToSPIRVPass.cpp @@ -20,8 +20,13 @@ namespace { /// A pass converting MLIR Func operations into the SPIR-V dialect. -class ConvertFuncToSPIRVPass +struct ConvertFuncToSPIRVPass : public ConvertFuncToSPIRVBase { + ConvertFuncToSPIRVPass() = default; + + ConvertFuncToSPIRVPass(const ConvertFuncToSPIRVBaseOptions &options) + : ConvertFuncToSPIRVBase(options) {} + void runOnOperation() override; }; } // namespace @@ -49,3 +54,8 @@ std::unique_ptr> mlir::createConvertFuncToSPIRVPass() { return std::make_unique(); } + +std::unique_ptr> mlir::createConvertFuncToSPIRVPass( + const ConvertFuncToSPIRVBaseOptions &options) { + return std::make_unique(options); +} diff --git a/mlir/lib/Conversion/GPUCommon/GPUToLLVMConversion.cpp b/mlir/lib/Conversion/GPUCommon/GPUToLLVMConversion.cpp --- a/mlir/lib/Conversion/GPUCommon/GPUToLLVMConversion.cpp +++ b/mlir/lib/Conversion/GPUCommon/GPUToLLVMConversion.cpp @@ -49,11 +49,7 @@ public: GpuToLLVMConversionPass() = default; - GpuToLLVMConversionPass(bool kernelBarePtrCallConv) - : GpuToLLVMConversionPass() { - if (this->kernelBarePtrCallConv.getNumOccurrences() == 0) - this->kernelBarePtrCallConv = kernelBarePtrCallConv; - } + GpuToLLVMConversionPass(const GpuToLLVMConversionPassBaseOptions &options) : GpuToLLVMConversionPassBase(options) {} GpuToLLVMConversionPass(const GpuToLLVMConversionPass &other) : GpuToLLVMConversionPassBase(other) {} @@ -896,9 +892,12 @@ return success(); } -std::unique_ptr> -mlir::createGpuToLLVMConversionPass(bool kernelBarePtrCallConv) { - return std::make_unique(kernelBarePtrCallConv); +std::unique_ptr> mlir::createGpuToLLVMConversionPass() { + return std::make_unique(); +} + +std::unique_ptr> mlir::createGpuToLLVMConversionPass(const GpuToLLVMConversionPassBaseOptions &options) { + return std::make_unique(options); } void mlir::populateGpuToLLVMConversionPatterns(LLVMTypeConverter &converter, diff --git a/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp b/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp --- a/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp +++ b/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp @@ -154,9 +154,8 @@ struct LowerGpuOpsToNVVMOpsPass : public ConvertGpuOpsToNVVMOpsBase { LowerGpuOpsToNVVMOpsPass() = default; - LowerGpuOpsToNVVMOpsPass(unsigned indexBitwidth) { - this->indexBitwidth = indexBitwidth; - } + + LowerGpuOpsToNVVMOpsPass(const ConvertGpuOpsToNVVMOpsBaseOptions &options) : ConvertGpuOpsToNVVMOpsBase(options) {} void runOnOperation() override { gpu::GPUModuleOp m = getOperation(); @@ -287,7 +286,11 @@ "__nv_tanh"); } +std::unique_ptr> mlir::createLowerGpuOpsToNVVMOpsPass() { + return std::make_unique(); +} + std::unique_ptr> -mlir::createLowerGpuOpsToNVVMOpsPass(unsigned indexBitwidth) { - return std::make_unique(indexBitwidth); +mlir::createLowerGpuOpsToNVVMOpsPass(const ConvertGpuOpsToNVVMOpsBaseOptions &options) { + return std::make_unique(options); } diff --git a/mlir/lib/Conversion/GPUToROCDL/LowerGpuOpsToROCDLOps.cpp b/mlir/lib/Conversion/GPUToROCDL/LowerGpuOpsToROCDLOps.cpp --- a/mlir/lib/Conversion/GPUToROCDL/LowerGpuOpsToROCDLOps.cpp +++ b/mlir/lib/Conversion/GPUToROCDL/LowerGpuOpsToROCDLOps.cpp @@ -64,18 +64,8 @@ struct LowerGpuOpsToROCDLOpsPass : public ConvertGpuOpsToROCDLOpsBase { LowerGpuOpsToROCDLOpsPass() = default; - LowerGpuOpsToROCDLOpsPass(const std::string &chipset, unsigned indexBitwidth, - bool useBarePtrCallConv, - gpu::amd::Runtime runtime) { - if (this->chipset.getNumOccurrences() == 0) - this->chipset = chipset; - if (this->indexBitwidth.getNumOccurrences() == 0) - this->indexBitwidth = indexBitwidth; - if (this->useBarePtrCallConv.getNumOccurrences() == 0) - this->useBarePtrCallConv = useBarePtrCallConv; - if (this->runtime.getNumOccurrences() == 0) - this->runtime = runtime; - } + + LowerGpuOpsToROCDLOpsPass(const ConvertGpuOpsToROCDLOpsBaseOptions &options) : ConvertGpuOpsToROCDLOpsBase(options) {} void runOnOperation() override { gpu::GPUModuleOp m = getOperation(); @@ -219,11 +209,10 @@ "__ocml_tanh_f64"); } -std::unique_ptr> -mlir::createLowerGpuOpsToROCDLOpsPass(const std::string &chipset, - unsigned indexBitwidth, - bool useBarePtrCallConv, - gpu::amd::Runtime runtime) { - return std::make_unique( - chipset, indexBitwidth, useBarePtrCallConv, runtime); +std::unique_ptr> mlir::createLowerGpuOpsToROCDLOpsPass() { + return std::make_unique(); +} + +std::unique_ptr> mlir::createLowerGpuOpsToROCDLOpsPass(const ConvertGpuOpsToROCDLOpsBaseOptions &options) { + return std::make_unique(options); } diff --git a/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRVPass.cpp b/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRVPass.cpp --- a/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRVPass.cpp +++ b/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRVPass.cpp @@ -37,12 +37,12 @@ /// 2) Lower the body of the spirv::ModuleOp. class GPUToSPIRVPass : public ConvertGPUToSPIRVBase { public: - explicit GPUToSPIRVPass(bool mapMemorySpace) - : mapMemorySpace(mapMemorySpace) {} - void runOnOperation() override; + GPUToSPIRVPass() = default; + + GPUToSPIRVPass(const ConvertGPUToSPIRVBaseOptions &options) + : ConvertGPUToSPIRVBase(options) {} -private: - bool mapMemorySpace; + void runOnOperation() override; }; } // namespace @@ -92,7 +92,11 @@ return signalPassFailure(); } +std::unique_ptr> mlir::createConvertGPUToSPIRVPass() { + return std::make_unique(); +} + std::unique_ptr> -mlir::createConvertGPUToSPIRVPass(bool mapMemorySpace) { - return std::make_unique(mapMemorySpace); +mlir::createConvertGPUToSPIRVPass(const ConvertGPUToSPIRVBaseOptions &options) { + return std::make_unique(options); } diff --git a/mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp b/mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp --- a/mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp +++ b/mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp @@ -2045,6 +2045,8 @@ struct MemRefToLLVMPass : public ConvertMemRefToLLVMBase { MemRefToLLVMPass() = default; + MemRefToLLVMPass(const ConvertMemRefToLLVMBaseOptions &options) : ConvertMemRefToLLVMBase(options) {} + void runOnOperation() override { Operation *op = getOperation(); const auto &dataLayoutAnalysis = getAnalysis(); @@ -2074,3 +2076,7 @@ std::unique_ptr mlir::createMemRefToLLVMPass() { return std::make_unique(); } + +std::unique_ptr mlir::createMemRefToLLVMPass(const ConvertMemRefToLLVMBaseOptions &options) { + return std::make_unique(options); +} diff --git a/mlir/lib/Conversion/MemRefToSPIRV/MemRefToSPIRVPass.cpp b/mlir/lib/Conversion/MemRefToSPIRV/MemRefToSPIRVPass.cpp --- a/mlir/lib/Conversion/MemRefToSPIRV/MemRefToSPIRVPass.cpp +++ b/mlir/lib/Conversion/MemRefToSPIRV/MemRefToSPIRVPass.cpp @@ -20,8 +20,13 @@ namespace { /// A pass converting MLIR MemRef operations into the SPIR-V dialect. -class ConvertMemRefToSPIRVPass +struct ConvertMemRefToSPIRVPass : public ConvertMemRefToSPIRVBase { + ConvertMemRefToSPIRVPass() = default; + + ConvertMemRefToSPIRVPass(const ConvertMemRefToSPIRVBaseOptions &options) + : ConvertMemRefToSPIRVBase(options) {} + void runOnOperation() override; }; } // namespace @@ -59,3 +64,8 @@ std::unique_ptr> mlir::createConvertMemRefToSPIRVPass() { return std::make_unique(); } + +std::unique_ptr> mlir::createConvertMemRefToSPIRVPass( + const ConvertMemRefToSPIRVBaseOptions &options) { + return std::make_unique(options); +} diff --git a/mlir/lib/Conversion/PassDetail.h b/mlir/lib/Conversion/PassDetail.h --- a/mlir/lib/Conversion/PassDetail.h +++ b/mlir/lib/Conversion/PassDetail.h @@ -107,6 +107,7 @@ class ArmNeonDialect; } // namespace arm_neon +#define GEN_PASS_OPTIONS #define GEN_PASS_CLASSES #include "mlir/Conversion/Passes.h.inc" diff --git a/mlir/lib/Conversion/SCFToGPU/SCFToGPUPass.cpp b/mlir/lib/Conversion/SCFToGPU/SCFToGPUPass.cpp --- a/mlir/lib/Conversion/SCFToGPU/SCFToGPUPass.cpp +++ b/mlir/lib/Conversion/SCFToGPU/SCFToGPUPass.cpp @@ -28,10 +28,9 @@ // walk the function recursively to avoid considering nested loops. struct ForLoopMapper : public ConvertAffineForToGPUBase { ForLoopMapper() = default; - ForLoopMapper(unsigned numBlockDims, unsigned numThreadDims) { - this->numBlockDims = numBlockDims; - this->numThreadDims = numThreadDims; - } + + ForLoopMapper(const ConvertAffineForToGPUBaseOptions &options) + : ConvertAffineForToGPUBase(options) {} void runOnOperation() override { for (Operation &op : @@ -62,15 +61,17 @@ } // namespace -std::unique_ptr> -mlir::createAffineForToGPUPass(unsigned numBlockDims, unsigned numThreadDims) { - return std::make_unique(numBlockDims, numThreadDims); -} std::unique_ptr> mlir::createAffineForToGPUPass() { return std::make_unique(); } +std::unique_ptr> +mlir::createAffineForToGPUPass( + const ConvertAffineForToGPUBaseOptions &options) { + return std::make_unique(options); +} + std::unique_ptr mlir::createParallelLoopToGpuPass() { return std::make_unique(); } diff --git a/mlir/lib/Conversion/TensorToSPIRV/TensorToSPIRVPass.cpp b/mlir/lib/Conversion/TensorToSPIRV/TensorToSPIRVPass.cpp --- a/mlir/lib/Conversion/TensorToSPIRV/TensorToSPIRVPass.cpp +++ b/mlir/lib/Conversion/TensorToSPIRV/TensorToSPIRVPass.cpp @@ -22,8 +22,13 @@ namespace { /// A pass converting MLIR Tensor operations into the SPIR-V dialect. -class ConvertTensorToSPIRVPass +struct ConvertTensorToSPIRVPass : public ConvertTensorToSPIRVBase { + ConvertTensorToSPIRVPass() = default; + + ConvertTensorToSPIRVPass(const ConvertTensorToSPIRVBaseOptions &options) + : ConvertTensorToSPIRVBase(options) {} + void runOnOperation() override { MLIRContext *context = &getContext(); Operation *op = getOperation(); @@ -52,3 +57,8 @@ std::unique_ptr> mlir::createConvertTensorToSPIRVPass() { return std::make_unique(); } + +std::unique_ptr> mlir::createConvertTensorToSPIRVPass( + const ConvertTensorToSPIRVBaseOptions &options) { + return std::make_unique(options); +} diff --git a/mlir/lib/Conversion/TosaToArith/TosaToArithPass.cpp b/mlir/lib/Conversion/TosaToArith/TosaToArithPass.cpp --- a/mlir/lib/Conversion/TosaToArith/TosaToArithPass.cpp +++ b/mlir/lib/Conversion/TosaToArith/TosaToArithPass.cpp @@ -27,6 +27,11 @@ namespace { struct TosaToArith : public TosaToArithBase { public: + TosaToArith() = default; + + TosaToArith(const TosaToArithBaseOptions &options) + : TosaToArithBase(options) {} + void runOnOperation() override { RewritePatternSet patterns(&getContext()); ConversionTarget target(getContext()); @@ -51,3 +56,8 @@ std::unique_ptr mlir::tosa::createTosaToArith() { return std::make_unique(); } + +std::unique_ptr +mlir::tosa::createTosaToArith(const TosaToArithBaseOptions &options) { + return std::make_unique(options); +} diff --git a/mlir/lib/Conversion/VectorToGPU/VectorToGPU.cpp b/mlir/lib/Conversion/VectorToGPU/VectorToGPU.cpp --- a/mlir/lib/Conversion/VectorToGPU/VectorToGPU.cpp +++ b/mlir/lib/Conversion/VectorToGPU/VectorToGPU.cpp @@ -884,9 +884,9 @@ struct ConvertVectorToGPUPass : public ConvertVectorToGPUBase { - explicit ConvertVectorToGPUPass(bool useNvGpu_) { - useNvGpu.setValue(useNvGpu_); - } + ConvertVectorToGPUPass() = default; + + ConvertVectorToGPUPass(const ConvertVectorToGPUBaseOptions &options) : ConvertVectorToGPUBase(options) {} void runOnOperation() override { RewritePatternSet patterns(&getContext()); @@ -906,6 +906,10 @@ } // namespace -std::unique_ptr mlir::createConvertVectorToGPUPass(bool useNvGpu) { - return std::make_unique(useNvGpu); +std::unique_ptr mlir::createConvertVectorToGPUPass() { + return std::make_unique(); +} + +std::unique_ptr mlir::createConvertVectorToGPUPass(const ConvertVectorToGPUBaseOptions &options) { + return std::make_unique(options); } diff --git a/mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVMPass.cpp b/mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVMPass.cpp --- a/mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVMPass.cpp +++ b/mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVMPass.cpp @@ -32,14 +32,11 @@ namespace { struct LowerVectorToLLVMPass : public ConvertVectorToLLVMBase { - LowerVectorToLLVMPass(const LowerVectorToLLVMOptions &options) { - this->reassociateFPReductions = options.reassociateFPReductions; - this->force32BitVectorIndices = options.force32BitVectorIndices; - this->armNeon = options.armNeon; - this->armSVE = options.armSVE; - this->amx = options.amx; - this->x86Vector = options.x86Vector; - } + LowerVectorToLLVMPass() = default; + + LowerVectorToLLVMPass(const ConvertVectorToLLVMBaseOptions &options) + : ConvertVectorToLLVMBase(options) {} + // Override explicitly to allow conditional dialect dependence. void getDependentDialects(DialectRegistry ®istry) const override { registry.insert(); @@ -113,7 +110,11 @@ signalPassFailure(); } -std::unique_ptr> -mlir::createConvertVectorToLLVMPass(const LowerVectorToLLVMOptions &options) { +std::unique_ptr> mlir::createConvertVectorToLLVMPass() { + return std::make_unique(); +} + +std::unique_ptr> mlir::createConvertVectorToLLVMPass( + const ConvertVectorToLLVMBaseOptions &options) { return std::make_unique(options); } diff --git a/mlir/lib/Dialect/Affine/Transforms/PassDetail.h b/mlir/lib/Dialect/Affine/Transforms/PassDetail.h --- a/mlir/lib/Dialect/Affine/Transforms/PassDetail.h +++ b/mlir/lib/Dialect/Affine/Transforms/PassDetail.h @@ -34,6 +34,7 @@ class VectorDialect; } // namespace vector +#define GEN_PASS_OPTIONS #define GEN_PASS_CLASSES #include "mlir/Dialect/Affine/Passes.h.inc" diff --git a/mlir/lib/Dialect/Arithmetic/Transforms/PassDetail.h b/mlir/lib/Dialect/Arithmetic/Transforms/PassDetail.h --- a/mlir/lib/Dialect/Arithmetic/Transforms/PassDetail.h +++ b/mlir/lib/Dialect/Arithmetic/Transforms/PassDetail.h @@ -26,6 +26,7 @@ class MemRefDialect; } // namespace memref +#define GEN_PASS_OPTIONS #define GEN_PASS_CLASSES #include "mlir/Dialect/Arithmetic/Transforms/Passes.h.inc" diff --git a/mlir/lib/Dialect/Async/Transforms/PassDetail.h b/mlir/lib/Dialect/Async/Transforms/PassDetail.h --- a/mlir/lib/Dialect/Async/Transforms/PassDetail.h +++ b/mlir/lib/Dialect/Async/Transforms/PassDetail.h @@ -27,6 +27,7 @@ class SCFDialect; } // namespace scf +#define GEN_PASS_OPTIONS #define GEN_PASS_CLASSES #include "mlir/Dialect/Async/Passes.h.inc" diff --git a/mlir/lib/Dialect/Bufferization/Transforms/PassDetail.h b/mlir/lib/Dialect/Bufferization/Transforms/PassDetail.h --- a/mlir/lib/Dialect/Bufferization/Transforms/PassDetail.h +++ b/mlir/lib/Dialect/Bufferization/Transforms/PassDetail.h @@ -27,6 +27,7 @@ class MemRefDialect; } // namespace memref +#define GEN_PASS_OPTIONS #define GEN_PASS_CLASSES #include "mlir/Dialect/Bufferization/Transforms/Passes.h.inc" diff --git a/mlir/lib/Dialect/Func/Transforms/PassDetail.h b/mlir/lib/Dialect/Func/Transforms/PassDetail.h --- a/mlir/lib/Dialect/Func/Transforms/PassDetail.h +++ b/mlir/lib/Dialect/Func/Transforms/PassDetail.h @@ -25,6 +25,7 @@ class MemRefDialect; } // namespace memref +#define GEN_PASS_OPTIONS #define GEN_PASS_CLASSES #include "mlir/Dialect/Func/Transforms/Passes.h.inc" diff --git a/mlir/lib/Dialect/GPU/Transforms/PassDetail.h b/mlir/lib/Dialect/GPU/Transforms/PassDetail.h --- a/mlir/lib/Dialect/GPU/Transforms/PassDetail.h +++ b/mlir/lib/Dialect/GPU/Transforms/PassDetail.h @@ -17,6 +17,7 @@ namespace mlir { +#define GEN_PASS_OPTIONS #define GEN_PASS_CLASSES #include "mlir/Dialect/GPU/Transforms/Passes.h.inc" diff --git a/mlir/lib/Dialect/LLVMIR/Transforms/PassDetail.h b/mlir/lib/Dialect/LLVMIR/Transforms/PassDetail.h --- a/mlir/lib/Dialect/LLVMIR/Transforms/PassDetail.h +++ b/mlir/lib/Dialect/LLVMIR/Transforms/PassDetail.h @@ -16,6 +16,7 @@ class FuncOp; } // namespace func +#define GEN_PASS_OPTIONS #define GEN_PASS_CLASSES #include "mlir/Dialect/LLVMIR/Transforms/Passes.h.inc" diff --git a/mlir/lib/Dialect/Linalg/Transforms/PassDetail.h b/mlir/lib/Dialect/Linalg/Transforms/PassDetail.h --- a/mlir/lib/Dialect/Linalg/Transforms/PassDetail.h +++ b/mlir/lib/Dialect/Linalg/Transforms/PassDetail.h @@ -44,6 +44,7 @@ class VectorDialect; } // namespace vector +#define GEN_PASS_OPTIONS #define GEN_PASS_CLASSES #include "mlir/Dialect/Linalg/Passes.h.inc" diff --git a/mlir/lib/Dialect/NVGPU/Transforms/PassDetail.h b/mlir/lib/Dialect/NVGPU/Transforms/PassDetail.h --- a/mlir/lib/Dialect/NVGPU/Transforms/PassDetail.h +++ b/mlir/lib/Dialect/NVGPU/Transforms/PassDetail.h @@ -25,6 +25,7 @@ class VectorDialect; } // namespace vector +#define GEN_PASS_OPTIONS #define GEN_PASS_CLASSES #include "mlir/Dialect/NVGPU/Passes.h.inc" diff --git a/mlir/lib/Dialect/SCF/Transforms/PassDetail.h b/mlir/lib/Dialect/SCF/Transforms/PassDetail.h --- a/mlir/lib/Dialect/SCF/Transforms/PassDetail.h +++ b/mlir/lib/Dialect/SCF/Transforms/PassDetail.h @@ -35,6 +35,7 @@ class TensorDialect; } // namespace tensor +#define GEN_PASS_OPTIONS #define GEN_PASS_CLASSES #include "mlir/Dialect/SCF/Transforms/Passes.h.inc" diff --git a/mlir/lib/Dialect/SPIRV/Transforms/PassDetail.h b/mlir/lib/Dialect/SPIRV/Transforms/PassDetail.h --- a/mlir/lib/Dialect/SPIRV/Transforms/PassDetail.h +++ b/mlir/lib/Dialect/SPIRV/Transforms/PassDetail.h @@ -18,6 +18,7 @@ class ModuleOp; } // namespace spirv +#define GEN_PASS_OPTIONS #define GEN_PASS_CLASSES #include "mlir/Dialect/SPIRV/Transforms/Passes.h.inc" diff --git a/mlir/lib/Dialect/Shape/Transforms/PassDetail.h b/mlir/lib/Dialect/Shape/Transforms/PassDetail.h --- a/mlir/lib/Dialect/Shape/Transforms/PassDetail.h +++ b/mlir/lib/Dialect/Shape/Transforms/PassDetail.h @@ -22,6 +22,7 @@ class MemRefDialect; } // namespace memref +#define GEN_PASS_OPTIONS #define GEN_PASS_CLASSES #include "mlir/Dialect/Shape/Transforms/Passes.h.inc" diff --git a/mlir/lib/Dialect/SparseTensor/Pipelines/SparseTensorPipelines.cpp b/mlir/lib/Dialect/SparseTensor/Pipelines/SparseTensorPipelines.cpp --- a/mlir/lib/Dialect/SparseTensor/Pipelines/SparseTensorPipelines.cpp +++ b/mlir/lib/Dialect/SparseTensor/Pipelines/SparseTensorPipelines.cpp @@ -71,7 +71,17 @@ pm.addNestedPass(createConvertVectorToSCFPass()); pm.addNestedPass(createConvertSCFToCFPass()); pm.addPass(createLowerAffinePass()); - pm.addPass(createConvertVectorToLLVMPass(options.lowerVectorToLLVMOptions())); + + ConvertVectorToLLVMBaseOptions vectorToLLVMOptions; + vectorToLLVMOptions.reassociateFPReductions = options.reassociateFPReductions; + vectorToLLVMOptions.force32BitVectorIndices = options.indexOptimizations; + vectorToLLVMOptions.armNeon = options.armNeon; + vectorToLLVMOptions.armSVE = options.armSVE; + vectorToLLVMOptions.amx = options.amx; + vectorToLLVMOptions.x86Vector = options.x86Vector; + + pm.addPass(createConvertVectorToLLVMPass(vectorToLLVMOptions)); + pm.addPass(createMemRefToLLVMPass()); pm.addNestedPass(createConvertComplexToStandardPass()); pm.addNestedPass( diff --git a/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorPasses.cpp b/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorPasses.cpp --- a/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorPasses.cpp +++ b/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorPasses.cpp @@ -25,6 +25,13 @@ namespace { +//===----------------------------------------------------------------------===// +// Passes options. +//===----------------------------------------------------------------------===// + +#define GEN_PASS_OPTIONS +#include "mlir/Dialect/SparseTensor/Transforms/Passes.h.inc" + //===----------------------------------------------------------------------===// // Passes declaration. //===----------------------------------------------------------------------===// diff --git a/mlir/lib/Dialect/Tensor/Transforms/PassDetail.h b/mlir/lib/Dialect/Tensor/Transforms/PassDetail.h --- a/mlir/lib/Dialect/Tensor/Transforms/PassDetail.h +++ b/mlir/lib/Dialect/Tensor/Transforms/PassDetail.h @@ -26,6 +26,7 @@ class SCFDialect; } // namespace scf +#define GEN_PASS_OPTIONS #define GEN_PASS_CLASSES #include "mlir/Dialect/Tensor/Transforms/Passes.h.inc" diff --git a/mlir/lib/Dialect/Transform/Transforms/CheckUses.cpp b/mlir/lib/Dialect/Transform/Transforms/CheckUses.cpp --- a/mlir/lib/Dialect/Transform/Transforms/CheckUses.cpp +++ b/mlir/lib/Dialect/Transform/Transforms/CheckUses.cpp @@ -361,6 +361,9 @@ DenseMap> reachableFromCache; }; +#define GEN_PASS_OPTIONS +#include "mlir/Dialect/Transform/Transforms/Passes.h.inc" + #define GEN_PASS_CLASSES #include "mlir/Dialect/Transform/Transforms/Passes.h.inc" diff --git a/mlir/lib/Dialect/Vector/Transforms/PassDetail.h b/mlir/lib/Dialect/Vector/Transforms/PassDetail.h --- a/mlir/lib/Dialect/Vector/Transforms/PassDetail.h +++ b/mlir/lib/Dialect/Vector/Transforms/PassDetail.h @@ -22,6 +22,7 @@ class MemRefDialect; } // namespace memref +#define GEN_PASS_OPTIONS #define GEN_PASS_CLASSES #include "mlir/Dialect/Vector/Transforms/Passes.h.inc" diff --git a/mlir/lib/Transforms/PassDetail.h b/mlir/lib/Transforms/PassDetail.h --- a/mlir/lib/Transforms/PassDetail.h +++ b/mlir/lib/Transforms/PassDetail.h @@ -14,8 +14,11 @@ #include "mlir/Transforms/Passes.h" namespace mlir { + +#define GEN_PASS_OPTIONS #define GEN_PASS_CLASSES #include "mlir/Transforms/Passes.h.inc" + } // namespace mlir #endif // TRANSFORMS_PASSDETAIL_H_ diff --git a/mlir/tools/mlir-tblgen/PassGen.cpp b/mlir/tools/mlir-tblgen/PassGen.cpp --- a/mlir/tools/mlir-tblgen/PassGen.cpp +++ b/mlir/tools/mlir-tblgen/PassGen.cpp @@ -27,6 +27,16 @@ groupName("name", llvm::cl::desc("The name of this group of passes"), llvm::cl::cat(passGenCat)); +const char *const optionsStruct = R"( +//===----------------------------------------------------------------------===// +// {0} +//===----------------------------------------------------------------------===// + +struct {0}BaseOptions { +{1} +}; +)"; + //===----------------------------------------------------------------------===// // GEN: Pass base class generation //===----------------------------------------------------------------------===// @@ -87,12 +97,57 @@ protected: )"; +const char *const optionsForwardingConstructor = R"( +{0}Base(const {0}BaseOptions &options) : {0}Base() {{ + {1} +} +)"; + /// Registration for a single dependent dialect, to be inserted for each /// dependent dialect in the `getDependentDialects` above. const char *const dialectRegistrationTemplate = R"( registry.insert<{0}>(); )"; +/// Emit the body of the struct to be used for providing custom options through +/// the C++ APIs. +static void emitOptionsStructBody(llvm::ArrayRef options, raw_ostream &os) { + for (const PassOption &opt : options) { + os.indent(2) << llvm::formatv("{0} {1}", opt.getType(), + opt.getCppVariableName()); + + if (Optional defaultVal = opt.getDefaultValue()) + os << " = " << defaultVal; + + os << ";\n"; + } +} + +static void emitOptionsStruct(const Pass &pass, raw_ostream &os) { + StringRef passName = pass.getDef()->getName(); + ArrayRef options = pass.getOptions(); + + if (options.empty()) + return; + + std::string structBody; + llvm::raw_string_ostream structOs(structBody); + emitOptionsStructBody(options, structOs); + + os << llvm::formatv(optionsStruct, passName, structBody); +} + +static void emitOptionsStructs(ArrayRef passes, raw_ostream &os) { + os << "#ifdef GEN_PASS_OPTIONS\n"; + + for (const Pass &pass : passes) { + emitOptionsStruct(pass, os); + } + + os << "#undef GEN_PASS_OPTIONS\n"; + os << "#endif // GEN_PASS_OPTIONS\n"; +} + /// Emit the declarations for each of the pass options. static void emitPassOptionDecls(const Pass &pass, raw_ostream &os) { for (const PassOption &opt : pass.getOptions()) { @@ -110,6 +165,25 @@ } } +static void emitOptionsForwardingConstructorBody(ArrayRef options, raw_ostream &os) { + for (const PassOption &opt : options) + os << llvm::formatv("{0} = options.{0};\n", opt.getCppVariableName()); +} + +static void emitOptionsForwardingConstructor(const Pass &pass, raw_ostream &os) { + StringRef passName = pass.getDef()->getName(); + ArrayRef options = pass.getOptions(); + + if (options.empty()) + return; + + std::string body; + llvm::raw_string_ostream bodyOs(body); + emitOptionsForwardingConstructorBody(options, bodyOs); + + os << llvm::formatv(optionsForwardingConstructor, passName, body); +} + /// Emit the declarations for each of the pass statistics. static void emitPassStatisticDecls(const Pass &pass, raw_ostream &os) { for (const PassStatistic &stat : pass.getStatistics()) { @@ -121,6 +195,7 @@ static void emitPassDecl(const Pass &pass, raw_ostream &os) { StringRef defName = pass.getDef()->getName(); + std::string dependentDialectRegistrations; { llvm::raw_string_ostream dialectsOs(dependentDialectRegistrations); @@ -128,9 +203,12 @@ dialectsOs << llvm::formatv(dialectRegistrationTemplate, dependentDialect); } + os << llvm::formatv(passDeclBegin, defName, pass.getBaseClass(), pass.getArgument(), pass.getSummary(), dependentDialectRegistrations); + + emitOptionsForwardingConstructor(pass, os); emitPassOptionDecls(pass, os); emitPassStatisticDecls(pass, os); os << "};\n"; @@ -205,6 +283,7 @@ for (const auto *def : recordKeeper.getAllDerivedDefinitions("PassBase")) passes.emplace_back(def); + emitOptionsStructs(passes, os); emitPassDecls(passes, os); emitRegistration(passes, os); } diff --git a/mlir/unittests/TableGen/PassGenTest.cpp b/mlir/unittests/TableGen/PassGenTest.cpp --- a/mlir/unittests/TableGen/PassGenTest.cpp +++ b/mlir/unittests/TableGen/PassGenTest.cpp @@ -15,18 +15,26 @@ #define GEN_PASS_REGISTRATION #include "PassGenTest.h.inc" +#define GEN_PASS_OPTIONS +#include "PassGenTest.h.inc" + #define GEN_PASS_CLASSES #include "PassGenTest.h.inc" struct TestPass : public TestPassBase { explicit TestPass(int v) : extraVal(v) {} + TestPass(int v, const TestPassBaseOptions &options) + : TestPassBase(options), extraVal(v) {} + void runOnOperation() override {} std::unique_ptr clone() const { return TestPassBase::clone(); } + unsigned getTestOption() const { return testOption; } + int extraVal; }; @@ -34,6 +42,11 @@ return std::make_unique(v); } +std::unique_ptr createTestPass(int v, + const TestPassBaseOptions &options) { + return std::make_unique(v, options); +} + TEST(PassGenTest, PassClone) { mlir::MLIRContext context; @@ -46,3 +59,18 @@ EXPECT_EQ(unwrap(origPass)->extraVal, unwrap(clonePass)->extraVal); } + +TEST(PassGenTest, PassOptions) { + mlir::MLIRContext context; + + TestPassBaseOptions options; + options.testOption = 57; + + const auto unwrap = [](const std::unique_ptr &pass) { + return static_cast(pass.get()); + }; + + const auto pass = createTestPass(10, options); + + EXPECT_EQ(unwrap(pass)->getTestOption(), 57); +} diff --git a/mlir/unittests/TableGen/passes.td b/mlir/unittests/TableGen/passes.td --- a/mlir/unittests/TableGen/passes.td +++ b/mlir/unittests/TableGen/passes.td @@ -15,5 +15,7 @@ let constructor = "::createTestPass()"; - let options = RewritePassUtils.options; + let options = [ + Option<"testOption", "testOption", "unsigned", "0", "Test option"> + ]; }