Building libMLIR.so currently fails with:
> /usr/bin/ld: /tmp/ccNzulEA.ltrans39.ltrans.o: in function `(anonymous namespace)::SerializeToHsacoPass::optimizeLlvm(llvm::Module&, llvm::TargetMachine&)':
> /builddir/build/BUILD/llvm-project-15.0.0.src/mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp:328: undefined reference to `mlir::makeOptimizingTransformer(unsigned int, unsigned int, llvm::TargetMachine*)'
This is because MLIRGPUTransforms depends on MLIRExecutionEngine in
https://github.com/llvm/llvm-project/blob/
61bb2e4ea82fc5499a271d70d4537383d1942208/mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp#L328,
but MLIRExecutionEngine is marked as excluded from libMLIR.so.
However, this code doesn't require the full execution engine: It
only performs middle-end optimization, and does not need any of
the JIT/codegen infrastructure. As such, split off a separate
library MLIRExecutionEngineUtils, which only contains that part
and is not excluded from libMLIR.so.
Fixes https://github.com/llvm/llvm-project/issues/54242.
Differential Revision: https://reviews.llvm.org/D125214
MLIRArithmetic
MLIRAsync
MLIRDataLayoutInterfaces
+ MLIRExecutionEngineUtils
MLIRGPUOps
MLIRIR
MLIRLLVMIR
PerfJITEvents)
endif(LLVM_USE_PERF)
+# Use a separate library for OptUtils, to avoid pulling in the entire JIT and
+# codegen infrastructure. Unlike MLIRExecutionEngine, this is part of
+# libMLIR.so.
+add_mlir_library(MLIRExecutionEngineUtils
+ OptUtils.cpp
+
+ ADDITIONAL_HEADER_DIRS
+ ${MLIR_MAIN_INCLUDE_DIR}/mlir/ExecutionEngine
+
+ DEPENDS
+ intrinsics_gen
+
+ LINK_COMPONENTS
+ Analysis
+ Core
+ Coroutines
+ AggressiveInstCombine
+ InstCombine
+ ScalarOpts
+ Vectorize
+ TransformUtils
+ IPO
+ Passes
+ )
+
add_mlir_library(MLIRExecutionEngine
ExecutionEngine.cpp
- OptUtils.cpp
EXCLUDE_FROM_LIBMLIR
${LLVM_JIT_LISTENER_LIB}
LINK_LIBS PUBLIC
+ MLIRExecutionEngineUtils
MLIRLLVMIR
MLIRLLVMToLLVMIRTranslation
MLIRTargetLLVMIRExport