Skip to content

Commit aef8177

Browse files
committed
Add CMake options to control dialect builds
This commit introduces several CMake options to conditionally enable or disable specific dialects and conversions. This allows for a more modular build and helps resolve build failures in configurations where certain dialects are not needed or are causing issues. Part-of: EISW-163563, EISW-170058, EISW-163564
1 parent ed2d649 commit aef8177

File tree

22 files changed

+114
-37
lines changed

22 files changed

+114
-37
lines changed

mlir/CMakeLists.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,24 @@ set(MLIR_PDLL_TABLEGEN_TARGET "${MLIR_PDLL_TABLEGEN_TARGET}" CACHE INTERNAL "")
217217
set(MLIR_SRC_SHARDER_TABLEGEN_EXE "${MLIR_SRC_SHARDER_TABLEGEN_EXE}" CACHE INTERNAL "")
218218
set(MLIR_SRC_SHARDER_TABLEGEN_TARGET "${MLIR_SRC_SHARDER_TABLEGEN_TARGET}" CACHE INTERNAL "")
219219

220+
# XeGPU Dialect Option (Default OFF)
221+
option(MLIR_DIALECT_XEGPU_ENABLE
222+
"Enable the XeGPU dialect."
223+
OFF)
224+
225+
if(MLIR_DIALECT_XEGPU_ENABLE)
226+
add_compile_definitions(MLIR_DIALECT_XEGPU_ENABLE)
227+
endif()
228+
229+
# TosaToTensor Conversion Option (Default OFF)
230+
option(MLIR_CONVERSION_TOSATOTENSOR_ENABLE
231+
"Enable TosaToTensor conversion"
232+
OFF)
233+
234+
if(MLIR_CONVERSION_TOSATOTENSOR_ENABLE)
235+
add_compile_definitions(MLIR_CONVERSION_TOSATOTENSOR_ENABLE)
236+
endif()
237+
220238
add_subdirectory(include/mlir)
221239
add_subdirectory(lib)
222240
# C API needs all dialects for registration, but should be built before tests.

mlir/include/mlir/Conversion/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,10 @@ add_public_tablegen_target(MLIRConversionPassIncGen)
77

88
add_mlir_doc(Passes ConversionPasses ./ -gen-pass-doc)
99

10+
if(MLIR_CONVERSION_TOSATOTENSOR_ENABLE)
11+
add_subdirectory(TosaToTensor)
12+
endif()
13+
if(MLIR_DIALECT_XEGPU_ENABLE)
14+
add_subdirectory(VectorToXeGPU)
15+
endif()
1016
add_subdirectory(ConvertToLLVM)

mlir/include/mlir/Conversion/Passes.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,19 @@
7171
#include "mlir/Conversion/TosaToLinalg/TosaToLinalg.h"
7272
#include "mlir/Conversion/TosaToMLProgram/TosaToMLProgram.h"
7373
#include "mlir/Conversion/TosaToSCF/TosaToSCF.h"
74+
#ifdef MLIR_CONVERSION_TOSATOTENSOR_ENABLE
7475
#include "mlir/Conversion/TosaToTensor/TosaToTensor.h"
76+
#endif
7577
#include "mlir/Conversion/UBToLLVM/UBToLLVM.h"
7678
#include "mlir/Conversion/UBToSPIRV/UBToSPIRV.h"
7779
#include "mlir/Conversion/VectorToArmSME/VectorToArmSME.h"
7880
#include "mlir/Conversion/VectorToGPU/VectorToGPU.h"
7981
#include "mlir/Conversion/VectorToLLVM/ConvertVectorToLLVMPass.h"
8082
#include "mlir/Conversion/VectorToSCF/VectorToSCF.h"
8183
#include "mlir/Conversion/VectorToSPIRV/VectorToSPIRVPass.h"
84+
#ifdef MLIR_DIALECT_XEGPU_ENABLE
8285
#include "mlir/Conversion/VectorToXeGPU/VectorToXeGPU.h"
86+
#endif
8387

8488
namespace mlir {
8589

mlir/include/mlir/Conversion/Passes.td

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1259,7 +1259,7 @@ def TosaToSCF : Pass<"tosa-to-scf"> {
12591259
//===----------------------------------------------------------------------===//
12601260
// TosaToTensor
12611261
//===----------------------------------------------------------------------===//
1262-
1262+
#ifdef MLIR_CONVERSION_TOSATOTENSOR_ENABLE
12631263
def TosaToTensor : Pass<"tosa-to-tensor"> {
12641264
let summary = "Lower TOSA to the Tensor dialect";
12651265
let dependentDialects = [
@@ -1272,6 +1272,7 @@ def TosaToTensor : Pass<"tosa-to-tensor"> {
12721272

12731273
let constructor = "tosa::createTosaToTensor()";
12741274
}
1275+
#endif
12751276

12761277
//===----------------------------------------------------------------------===//
12771278
// UBToLLVM
@@ -1464,6 +1465,7 @@ def ConvertVectorToSPIRV : Pass<"convert-vector-to-spirv"> {
14641465
// VectorToXeGPU
14651466
//===----------------------------------------------------------------------===//
14661467

1468+
#ifdef MLIR_DIALECT_XEGPU_ENABLE
14671469
def ConvertVectorToXeGPU : Pass<"convert-vector-to-xegpu"> {
14681470
let summary = "Lower the operations from the vector dialect into the XeGPU "
14691471
"dialect";
@@ -1473,5 +1475,6 @@ def ConvertVectorToXeGPU : Pass<"convert-vector-to-xegpu"> {
14731475
"vector::VectorDialect", "xegpu::XeGPUDialect"
14741476
];
14751477
}
1478+
#endif
14761479

14771480
#endif // MLIR_CONVERSION_PASSES
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
if(MLIR_CONVERSION_TOSATOTENSOR_ENABLE)
2+
set(LLVM_TARGET_DEFINITIONS Passes.td)
3+
mlir_tablegen(Passes.h.inc -gen-pass-decls -name TosaToTensor)
4+
mlir_tablegen(Passes.capi.h.inc -gen-pass-capi-header --prefix TosaToTensor)
5+
mlir_tablegen(Passes.capi.cpp.inc -gen-pass-capi-impl --prefix TosaToTensor)
6+
add_public_tablegen_target(MLIRTosaToTensorPassIncGen)
7+
endif()

mlir/include/mlir/Dialect/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,6 @@ add_subdirectory(UB)
4242
add_subdirectory(Utils)
4343
add_subdirectory(Vector)
4444
add_subdirectory(X86Vector)
45-
add_subdirectory(XeGPU)
45+
if(MLIR_DIALECT_XEGPU_ENABLE)
46+
add_subdirectory(XeGPU)
47+
endif()

mlir/include/mlir/InitAllDialects.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@
9494
#include "mlir/Dialect/Vector/Transforms/BufferizableOpInterfaceImpl.h"
9595
#include "mlir/Dialect/Vector/Transforms/SubsetOpInterfaceImpl.h"
9696
#include "mlir/Dialect/X86Vector/X86VectorDialect.h"
97+
#ifdef MLIR_DIALECT_XEGPU_ENABLE
9798
#include "mlir/Dialect/XeGPU/IR/XeGPU.h"
99+
#endif
98100
#include "mlir/IR/Dialect.h"
99101
#include "mlir/Interfaces/CastInterfaces.h"
100102
#include "mlir/Target/LLVM/NVVM/Target.h"
@@ -149,10 +151,13 @@ inline void registerAllDialects(DialectRegistry &registry) {
149151
transform::TransformDialect,
150152
ub::UBDialect,
151153
vector::VectorDialect,
152-
x86vector::X86VectorDialect,
153-
xegpu::XeGPUDialect>();
154+
x86vector::X86VectorDialect>();
154155
// clang-format on
155156

157+
#ifdef MLIR_DIALECT_XEGPU_ENABLE
158+
register.insert<xegpu::XeGPUDialect>();
159+
#endif
160+
156161
// Register all external models.
157162
affine::registerValueBoundsOpInterfaceExternalModels(registry);
158163
arith::registerBufferDeallocationOpInterfaceExternalModels(registry);

mlir/include/mlir/InitAllPasses.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@
4545
#include "mlir/Dialect/Tosa/Transforms/Passes.h"
4646
#include "mlir/Dialect/Transform/Transforms/Passes.h"
4747
#include "mlir/Dialect/Vector/Transforms/Passes.h"
48+
#ifdef MLIR_DIALECT_XEGPU_ENABLE
4849
#include "mlir/Dialect/XeGPU/Transforms/Passes.h"
50+
#endif
4951
#include "mlir/Transforms/Passes.h"
5052

5153
#include <cstdlib>
@@ -94,7 +96,10 @@ inline void registerAllPasses() {
9496
arm_sme::registerArmSMEPasses();
9597
arm_sve::registerArmSVEPasses();
9698
emitc::registerEmitCPasses();
99+
100+
#ifdef MLIR_DIALECT_XEGPU_ENABLE
97101
xegpu::registerXeGPUPasses();
102+
#endif
98103

99104
// Dialect pipelines
100105
bufferization::registerBufferizationPipelines();

mlir/lib/Conversion/CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,16 @@ add_subdirectory(TosaToArith)
6262
add_subdirectory(TosaToLinalg)
6363
add_subdirectory(TosaToMLProgram)
6464
add_subdirectory(TosaToSCF)
65-
add_subdirectory(TosaToTensor)
65+
if(MLIR_CONVERSION_TOSATOTENSOR_ENABLE)
66+
add_subdirectory(TosaToTensor)
67+
endif()
6668
add_subdirectory(UBToLLVM)
6769
add_subdirectory(UBToSPIRV)
6870
add_subdirectory(VectorToArmSME)
6971
add_subdirectory(VectorToGPU)
7072
add_subdirectory(VectorToLLVM)
7173
add_subdirectory(VectorToSCF)
7274
add_subdirectory(VectorToSPIRV)
73-
add_subdirectory(VectorToXeGPU)
75+
if(MLIR_DIALECT_XEGPU_ENABLE)
76+
add_subdirectory(VectorToXeGPU)
77+
endif()
Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
1-
add_mlir_conversion_library(MLIRTosaToTensor
2-
TosaToTensor.cpp
3-
TosaToTensorPass.cpp
1+
if(MLIR_CONVERSION_TOSATOTENSOR_ENABLE)
2+
add_mlir_conversion_library(MLIRTosaToTensor
3+
TosaToTensor.cpp
4+
TosaToTensorPass.cpp
45

5-
ADDITIONAL_HEADER_DIRS
6-
${MLIR_MAIN_INCLUDE_DIR}/mlir/Dialect/Tosa
7-
${MLIR_MAIN_INCLUDE_DIR}/mlir/IR
6+
ADDITIONAL_HEADER_DIRS
7+
${MLIR_MAIN_INCLUDE_DIR}/mlir/Dialect/Tosa
8+
${MLIR_MAIN_INCLUDE_DIR}/mlir/IR
89

9-
DEPENDS
10-
MLIRConversionPassIncGen
10+
DEPENDS
11+
MLIRConversionPassIncGen
1112

12-
LINK_LIBS PUBLIC
13-
MLIRTensorDialect
14-
MLIRTensorUtils
15-
MLIRIR
16-
MLIRPass
17-
MLIRTosaDialect
18-
MLIRTosaTransforms
19-
MLIRSupport
20-
)
13+
LINK_LIBS PUBLIC
14+
MLIRTensorDialect
15+
MLIRTensorUtils
16+
MLIRIR
17+
MLIRPass
18+
MLIRTosaDialect
19+
MLIRTosaTransforms
20+
MLIRSupport
21+
)
22+
endif()

0 commit comments

Comments
 (0)