[MLIR] Split off MLIRExecutionEngineUtils to fix libMLIR.so build (PR54242)
authorNikita Popov <npopov@redhat.com>
Mon, 9 May 2022 14:47:27 +0000 (16:47 +0200)
committerNikita Popov <npopov@redhat.com>
Tue, 10 May 2022 08:17:52 +0000 (10:17 +0200)
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

mlir/lib/Dialect/GPU/CMakeLists.txt
mlir/lib/ExecutionEngine/CMakeLists.txt

index 56587d4..50921ed 100644 (file)
@@ -69,6 +69,7 @@ add_mlir_dialect_library(MLIRGPUTransforms
   MLIRArithmetic
   MLIRAsync
   MLIRDataLayoutInterfaces
+  MLIRExecutionEngineUtils
   MLIRGPUOps
   MLIRIR
   MLIRLLVMIR
index e1f3047..687f88f 100644 (file)
@@ -23,9 +23,33 @@ if(LLVM_USE_PERF)
       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
 
@@ -56,6 +80,7 @@ add_mlir_library(MLIRExecutionEngine
   ${LLVM_JIT_LISTENER_LIB}
 
   LINK_LIBS PUBLIC
+  MLIRExecutionEngineUtils
   MLIRLLVMIR
   MLIRLLVMToLLVMIRTranslation
   MLIRTargetLLVMIRExport