From df852599f3a1c9faa3c20a1ac245e610a8ed3943 Mon Sep 17 00:00:00 2001 From: Krzysztof Drewniak Date: Tue, 18 Jul 2023 19:23:01 +0000 Subject: [PATCH] [mlir] Split up VectorToLLVM pass Currently, the VectorToLLVM patterns are built into a library along with the corresponding pass, which also pulls in all the platform-specific vector dialects (like AMXDialect) to apply all the vector to LLVM conversions. This causes dependency bloat when writing libraries - for example the GPU to LLVM passes, which use the vector to LLVM patterns, don't need the X86Vector dialect to be present at all. This commit partitions the library into VectorToLLVM and VectorToLLVMPass, where the latter pulls in all the other vector transformations. Reviewed By: nicolasvasilache, mehdi_amini Differential Revision: https://reviews.llvm.org/D158287 --- mlir/include/mlir/Conversion/Passes.h | 2 +- .../VectorToLLVM/ConvertVectorToLLVM.h | 4 --- .../VectorToLLVM/ConvertVectorToLLVMPass.h | 19 +++++++++++ .../Dialect/SparseTensor/Pipelines/Passes.h | 2 +- .../Conversion/VectorToLLVM/CMakeLists.txt | 32 +++++++++++++------ .../VectorToLLVM/ConvertVectorToLLVMPass.cpp | 2 +- .../SparseTensor/Pipelines/CMakeLists.txt | 2 +- mlir/test/lib/Dialect/GPU/CMakeLists.txt | 2 +- mlir/test/lib/Dialect/GPU/TestLowerToNVVM.cpp | 2 +- mlir/test/lib/Dialect/LLVM/CMakeLists.txt | 2 +- .../test/lib/Dialect/LLVM/TestLowerToLLVM.cpp | 2 +- mlir/tools/mlir-vulkan-runner/CMakeLists.txt | 2 +- .../mlir-vulkan-runner/mlir-vulkan-runner.cpp | 2 +- 13 files changed, 51 insertions(+), 24 deletions(-) create mode 100644 mlir/include/mlir/Conversion/VectorToLLVM/ConvertVectorToLLVMPass.h diff --git a/mlir/include/mlir/Conversion/Passes.h b/mlir/include/mlir/Conversion/Passes.h index 25f680ba6593..fc5e9adba114 100644 --- a/mlir/include/mlir/Conversion/Passes.h +++ b/mlir/include/mlir/Conversion/Passes.h @@ -63,7 +63,7 @@ #include "mlir/Conversion/UBToSPIRV/UBToSPIRV.h" #include "mlir/Conversion/VectorToArmSME/VectorToArmSME.h" #include "mlir/Conversion/VectorToGPU/VectorToGPU.h" -#include "mlir/Conversion/VectorToLLVM/ConvertVectorToLLVM.h" +#include "mlir/Conversion/VectorToLLVM/ConvertVectorToLLVMPass.h" #include "mlir/Conversion/VectorToSCF/VectorToSCF.h" #include "mlir/Conversion/VectorToSPIRV/VectorToSPIRVPass.h" diff --git a/mlir/include/mlir/Conversion/VectorToLLVM/ConvertVectorToLLVM.h b/mlir/include/mlir/Conversion/VectorToLLVM/ConvertVectorToLLVM.h index 0d5d1c8b5ffe..ecd33779236c 100644 --- a/mlir/include/mlir/Conversion/VectorToLLVM/ConvertVectorToLLVM.h +++ b/mlir/include/mlir/Conversion/VectorToLLVM/ConvertVectorToLLVM.h @@ -12,10 +12,6 @@ namespace mlir { class LLVMTypeConverter; -class Pass; - -#define GEN_PASS_DECL_CONVERTVECTORTOLLVMPASS -#include "mlir/Conversion/Passes.h.inc" /// Collect a set of patterns to convert from Vector contractions to LLVM Matrix /// Intrinsics. To lower to assembly, the LLVM flag -lower-matrix-intrinsics diff --git a/mlir/include/mlir/Conversion/VectorToLLVM/ConvertVectorToLLVMPass.h b/mlir/include/mlir/Conversion/VectorToLLVM/ConvertVectorToLLVMPass.h new file mode 100644 index 000000000000..4661d31b6364 --- /dev/null +++ b/mlir/include/mlir/Conversion/VectorToLLVM/ConvertVectorToLLVMPass.h @@ -0,0 +1,19 @@ +//===- ConvertVectorToLLVMPass.h - Pass to check Vector->LLVM --- --===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +#ifndef MLIR_CONVERSION_VECTORTOLLVM_CONVERTVECTORTOLLVMPASS_H_ +#define MLIR_CONVERSION_VECTORTOLLVM_CONVERTVECTORTOLLVMPASS_H_ + +#include "mlir/Conversion/VectorToLLVM/ConvertVectorToLLVM.h" + +namespace mlir { +class Pass; + +#define GEN_PASS_DECL_CONVERTVECTORTOLLVMPASS +#include "mlir/Conversion/Passes.h.inc" +} // namespace mlir +#endif // MLIR_CONVERSION_VECTORTOLLVM_CONVERTVECTORTOLLVMPASS_H_ diff --git a/mlir/include/mlir/Dialect/SparseTensor/Pipelines/Passes.h b/mlir/include/mlir/Dialect/SparseTensor/Pipelines/Passes.h index 5deab8321cbc..63040b152a86 100644 --- a/mlir/include/mlir/Dialect/SparseTensor/Pipelines/Passes.h +++ b/mlir/include/mlir/Dialect/SparseTensor/Pipelines/Passes.h @@ -13,7 +13,7 @@ #ifndef MLIR_DIALECT_SPARSETENSOR_PIPELINES_PASSES_H_ #define MLIR_DIALECT_SPARSETENSOR_PIPELINES_PASSES_H_ -#include "mlir/Conversion/VectorToLLVM/ConvertVectorToLLVM.h" +#include "mlir/Conversion/VectorToLLVM/ConvertVectorToLLVMPass.h" #include "mlir/Dialect/SparseTensor/Transforms/Passes.h" #include "mlir/Pass/PassOptions.h" diff --git a/mlir/lib/Conversion/VectorToLLVM/CMakeLists.txt b/mlir/lib/Conversion/VectorToLLVM/CMakeLists.txt index bb92d6506054..5fbb50f62395 100644 --- a/mlir/lib/Conversion/VectorToLLVM/CMakeLists.txt +++ b/mlir/lib/Conversion/VectorToLLVM/CMakeLists.txt @@ -1,6 +1,6 @@ add_mlir_conversion_library(MLIRVectorToLLVM + PARTIAL_SOURCES_INTENDED ConvertVectorToLLVM.cpp - ConvertVectorToLLVMPass.cpp ADDITIONAL_HEADER_DIRS ${MLIR_MAIN_INCLUDE_DIR}/mlir/Conversion/VectorToLLVM @@ -14,14 +14,6 @@ add_mlir_conversion_library(MLIRVectorToLLVM LINK_LIBS PUBLIC MLIRArithDialect - MLIRArmNeonDialect - MLIRArmSMEDialect - MLIRArmSMETransforms - MLIRVectorToArmSME - MLIRArmSVEDialect - MLIRArmSVETransforms - MLIRAMXDialect - MLIRAMXTransforms MLIRLLVMCommonConversion MLIRLLVMDialect MLIRMemRefDialect @@ -29,6 +21,26 @@ add_mlir_conversion_library(MLIRVectorToLLVM MLIRTransforms MLIRVectorDialect MLIRVectorTransforms + ) + +add_mlir_conversion_library(MLIRVectorToLLVMPass + PARTIAL_SOURCES_INTENDED + + ConvertVectorToLLVMPass.cpp + ADDITIONAL_HEADER_DIRS + ${MLIR_MAIN_INCLUDE_DIR}/mlir/Conversion/VectorToLLVM + + LINK_LIBS PUBLIC + MLIRVectorToLLVM + + MLIRArmNeonDialect + MLIRArmSMEDialect + MLIRArmSMETransforms + MLIRArmSVEDialect + MLIRArmSVETransforms + MLIRVectorToArmSME + MLIRAMXDialect + MLIRAMXTransforms MLIRX86VectorDialect MLIRX86VectorTransforms - ) +) diff --git a/mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVMPass.cpp b/mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVMPass.cpp index 04570a750822..2929823bad32 100644 --- a/mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVMPass.cpp +++ b/mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVMPass.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "mlir/Conversion/VectorToLLVM/ConvertVectorToLLVM.h" +#include "mlir/Conversion/VectorToLLVM/ConvertVectorToLLVMPass.h" #include "mlir/Conversion/LLVMCommon/ConversionTarget.h" #include "mlir/Conversion/LLVMCommon/TypeConverter.h" diff --git a/mlir/lib/Dialect/SparseTensor/Pipelines/CMakeLists.txt b/mlir/lib/Dialect/SparseTensor/Pipelines/CMakeLists.txt index 234a0d82babe..427dbe91be47 100644 --- a/mlir/lib/Dialect/SparseTensor/Pipelines/CMakeLists.txt +++ b/mlir/lib/Dialect/SparseTensor/Pipelines/CMakeLists.txt @@ -24,6 +24,6 @@ add_mlir_dialect_library(MLIRSparseTensorPipelines MLIRSparseTensorDialect MLIRSparseTensorTransforms MLIRTensorTransforms - MLIRVectorToLLVM + MLIRVectorToLLVMPass MLIRVectorTransforms ) diff --git a/mlir/test/lib/Dialect/GPU/CMakeLists.txt b/mlir/test/lib/Dialect/GPU/CMakeLists.txt index 80edd04b691a..3f20e5a6ecfc 100644 --- a/mlir/test/lib/Dialect/GPU/CMakeLists.txt +++ b/mlir/test/lib/Dialect/GPU/CMakeLists.txt @@ -27,7 +27,7 @@ set(LIBS MLIRTransforms MLIRTransformUtils MLIRTranslateLib - MLIRVectorToLLVM + MLIRVectorToLLVMPass ) add_mlir_library(MLIRGPUTestPasses diff --git a/mlir/test/lib/Dialect/GPU/TestLowerToNVVM.cpp b/mlir/test/lib/Dialect/GPU/TestLowerToNVVM.cpp index 5d0c420f65d5..48dce309c23b 100644 --- a/mlir/test/lib/Dialect/GPU/TestLowerToNVVM.cpp +++ b/mlir/test/lib/Dialect/GPU/TestLowerToNVVM.cpp @@ -22,7 +22,7 @@ #include "mlir/Conversion/NVGPUToNVVM/NVGPUToNVVM.h" #include "mlir/Conversion/ReconcileUnrealizedCasts/ReconcileUnrealizedCasts.h" #include "mlir/Conversion/SCFToControlFlow/SCFToControlFlow.h" -#include "mlir/Conversion/VectorToLLVM/ConvertVectorToLLVM.h" +#include "mlir/Conversion/VectorToLLVM/ConvertVectorToLLVMPass.h" #include "mlir/Conversion/VectorToSCF/VectorToSCF.h" #include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/Dialect/GPU/IR/GPUDialect.h" diff --git a/mlir/test/lib/Dialect/LLVM/CMakeLists.txt b/mlir/test/lib/Dialect/LLVM/CMakeLists.txt index 8446cd8d282c..734757ce79da 100644 --- a/mlir/test/lib/Dialect/LLVM/CMakeLists.txt +++ b/mlir/test/lib/Dialect/LLVM/CMakeLists.txt @@ -19,6 +19,6 @@ add_mlir_library(MLIRLLVMTestPasses MLIRReconcileUnrealizedCasts MLIRSCFToControlFlow MLIRTransforms - MLIRVectorToLLVM + MLIRVectorToLLVMPass MLIRVectorToSCF ) diff --git a/mlir/test/lib/Dialect/LLVM/TestLowerToLLVM.cpp b/mlir/test/lib/Dialect/LLVM/TestLowerToLLVM.cpp index 117aa2ba1ce7..8d61ec44214f 100644 --- a/mlir/test/lib/Dialect/LLVM/TestLowerToLLVM.cpp +++ b/mlir/test/lib/Dialect/LLVM/TestLowerToLLVM.cpp @@ -18,7 +18,7 @@ #include "mlir/Conversion/MemRefToLLVM/MemRefToLLVM.h" #include "mlir/Conversion/ReconcileUnrealizedCasts/ReconcileUnrealizedCasts.h" #include "mlir/Conversion/SCFToControlFlow/SCFToControlFlow.h" -#include "mlir/Conversion/VectorToLLVM/ConvertVectorToLLVM.h" +#include "mlir/Conversion/VectorToLLVM/ConvertVectorToLLVMPass.h" #include "mlir/Conversion/VectorToSCF/VectorToSCF.h" #include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/Dialect/LLVMIR/LLVMDialect.h" diff --git a/mlir/tools/mlir-vulkan-runner/CMakeLists.txt b/mlir/tools/mlir-vulkan-runner/CMakeLists.txt index e4bd9e4121e0..26d6caacb0a7 100644 --- a/mlir/tools/mlir-vulkan-runner/CMakeLists.txt +++ b/mlir/tools/mlir-vulkan-runner/CMakeLists.txt @@ -72,7 +72,7 @@ if (MLIR_ENABLE_VULKAN_RUNNER) MLIRTransforms MLIRTranslateLib MLIRVectorDialect - MLIRVectorToLLVM + MLIRVectorToLLVMPass ${Vulkan_LIBRARY} ) diff --git a/mlir/tools/mlir-vulkan-runner/mlir-vulkan-runner.cpp b/mlir/tools/mlir-vulkan-runner/mlir-vulkan-runner.cpp index c5e16f57af7c..0588fcd265f3 100644 --- a/mlir/tools/mlir-vulkan-runner/mlir-vulkan-runner.cpp +++ b/mlir/tools/mlir-vulkan-runner/mlir-vulkan-runner.cpp @@ -18,7 +18,7 @@ #include "mlir/Conversion/LLVMCommon/LoweringOptions.h" #include "mlir/Conversion/MemRefToLLVM/MemRefToLLVM.h" #include "mlir/Conversion/ReconcileUnrealizedCasts/ReconcileUnrealizedCasts.h" -#include "mlir/Conversion/VectorToLLVM/ConvertVectorToLLVM.h" +#include "mlir/Conversion/VectorToLLVM/ConvertVectorToLLVMPass.h" #include "mlir/Dialect/Arith/IR/Arith.h" #include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/Dialect/GPU/IR/GPUDialect.h"