Commit e17d9c11 authored by Valentin Churavy's avatar Valentin Churavy Committed by Stephen Neuendorffer
Browse files

[MLIR] Add support for libMLIR.so

Putting this up mainly for discussion on
how this should be done. I am interested in MLIR from
the Julia side and we currently have a strong preference
to dynamically linking against the LLVM shared library,
and would like to have a MLIR shared library.

This patch adds a new cmake function add_mlir_library()
which accumulates a list of targets to be compiled into
libMLIR.so.  Note that not all libraries make sense to
be compiled into libMLIR.so.  In particular, we want
to avoid libraries which primarily exist to support
certain tools (such as mlir-opt and mlir-cpu-runner).

Note that the resulting libMLIR.so depends on LLVM, but
does not contain any LLVM components.  As a result, it
is necessary to link with libLLVM.so to avoid linkage
errors. So, libMLIR.so requires LLVM_BUILD_LLVM_DYLIB=on

FYI, Currently it appears that LLVM_LINK_LLVM_DYLIB is broken
because mlir-tblgen is linked against libLLVM.so and
and independent LLVM components.

Previous version of this patch broke depencies on TableGen
targets.  This appears to be because it compiled all
libraries to OBJECT libraries (probably because cmake
is generating different target names).  Avoiding object
libraries results in correct dependencies.

(updated by Stephen Neuendorffer)

Differential Revision: https://reviews.llvm.org/D73130
parent 31e07d71
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -34,9 +34,11 @@ include_directories( ${MLIR_INCLUDE_DIR})

add_subdirectory(include/mlir)
add_subdirectory(lib)
add_subdirectory(tools)
add_subdirectory(unittests)
add_subdirectory(test)
# Tools needs to come late to ensure that MLIR_ALL_LIBS is populated.
# Generally things after this point may depend on MLIR_ALL_LIBS or libMLIR.so.
add_subdirectory(tools)

if( LLVM_INCLUDE_EXAMPLES )
  add_subdirectory(examples)
+8 −2
Original line number Diff line number Diff line
@@ -49,14 +49,20 @@ function(add_mlir_dialect dialect dialect_doc_filename)
  add_dependencies(mlir-doc ${dialect_doc_filename}DocGen)
endfunction()

# Declare a library which can be compiled in libMLIR.so
macro(add_mlir_library name)
  set_property(GLOBAL APPEND PROPERTY MLIR_ALL_LIBS ${name})
  add_llvm_library(${ARGV})
endmacro(add_mlir_library)

# Declare the library associated with a dialect.
function(add_mlir_dialect_library name)
  set_property(GLOBAL APPEND PROPERTY MLIR_DIALECT_LIBS ${name})
  add_llvm_library(${ARGV})
  add_mlir_library(${ARGV})
endfunction(add_mlir_dialect_library)

# Declare the library associated with a conversion.
function(add_mlir_conversion_library name)
  set_property(GLOBAL APPEND PROPERTY MLIR_CONVERSION_LIBS ${name})
  add_llvm_library(${ARGV})
  add_mlir_library(${ARGV})
endfunction(add_mlir_conversion_library)
+2 −2
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@ set(LLVM_OPTIONAL_SOURCES
  Verifier.cpp
  )

add_llvm_library(MLIRAnalysis
add_mlir_library(MLIRAnalysis
  CallGraph.cpp
  InferTypeOpInterface.cpp
  Liveness.cpp
@@ -35,7 +35,7 @@ add_llvm_library(MLIRAnalysis
  LLVMSupport
  )

add_llvm_library(MLIRLoopAnalysis
add_mlir_library(MLIRLoopAnalysis
  AffineAnalysis.cpp
  AffineStructures.cpp
  LoopAnalysis.cpp
+1 −2
Original line number Diff line number Diff line
@@ -12,12 +12,11 @@ add_subdirectory(SPIRV)
add_subdirectory(StandardOps)
add_subdirectory(VectorOps)


set(LLVM_OPTIONAL_SOURCES
  Traits.cpp
)

add_llvm_library(MLIRDialect
add_mlir_library(MLIRDialect
  Traits.cpp

  ADDITIONAL_HEADER_DIRS
+2 −2
Original line number Diff line number Diff line
@@ -3,7 +3,7 @@ set(LLVM_OPTIONAL_SOURCES
  CoreAPIs.cpp
  )

add_llvm_library(MLIREDSC
add_mlir_library(MLIREDSC
  Builders.cpp

  ADDITIONAL_HEADER_DIRS
@@ -15,7 +15,7 @@ add_llvm_library(MLIREDSC
  LLVMSupport
  )

add_llvm_library(MLIREDSCInterface
add_mlir_library(MLIREDSCInterface
  CoreAPIs.cpp

  ADDITIONAL_HEADER_DIRS
Loading