Skip to content

Commit

Permalink
[flang] Support linking to MLIR dylib
Browse files Browse the repository at this point in the history
Introduce a new `MLIR_LIBS` argument to `add_flang_library`, that uses
`mlir_target_link_libraries` to link the MLIR dylib alterantively
to the component libraries.  Use it, along with a few inline
`mlir_target_link_libraries` in tools, to support linking Flang to MLIR
dylib rather than the static libraries.

With these changes, the vast majority of Flang can be linked
dynamically.  The only parts still using static libraries are these
requiring MLIR test libraries, that are not included in the dylib.
  • Loading branch information
mgorny committed Jan 16, 2025
1 parent 226a9d7 commit 8d56cac
Show file tree
Hide file tree
Showing 27 changed files with 102 additions and 52 deletions.
3 changes: 2 additions & 1 deletion flang/cmake/modules/AddFlang.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ endmacro()

function(add_flang_library name)
set(options SHARED STATIC INSTALL_WITH_TOOLCHAIN)
set(multiValueArgs ADDITIONAL_HEADERS CLANG_LIBS)
set(multiValueArgs ADDITIONAL_HEADERS CLANG_LIBS MLIR_LIBS)
cmake_parse_arguments(ARG
"${options}"
""
Expand Down Expand Up @@ -66,6 +66,7 @@ function(add_flang_library name)
llvm_add_library(${name} ${LIBTYPE} ${ARG_UNPARSED_ARGUMENTS} ${srcs})

clang_target_link_libraries(${name} PRIVATE ${ARG_CLANG_LIBS})
mlir_target_link_libraries(${name} PRIVATE ${ARG_MLIR_LIBS})

if (TARGET ${name})

Expand Down
2 changes: 1 addition & 1 deletion flang/lib/Common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ add_flang_library(FortranCommon
LINK_COMPONENTS
Support

LINK_LIBS
MLIR_LIBS
MLIRIR
)
16 changes: 9 additions & 7 deletions flang/lib/Frontend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,6 @@ add_flang_library(flangFrontend
flangPasses
FIROpenACCSupport
FlangOpenMPTransforms
MLIRTransforms
MLIRBuiltinToLLVMIRTranslation
MLIRLLVMToLLVMIRTranslation
MLIRSCFToControlFlow
MLIRTargetLLVMIRImport
${dialect_libs}
${extension_libs}

LINK_COMPONENTS
Passes
Expand All @@ -63,6 +56,15 @@ add_flang_library(flangFrontend
FrontendOpenACC
FrontendOpenMP

MLIR_LIBS
MLIRTransforms
MLIRBuiltinToLLVMIRTranslation
MLIRLLVMToLLVMIRTranslation
MLIRSCFToControlFlow
MLIRTargetLLVMIRImport
${dialect_libs}
${extension_libs}

CLANG_LIBS
clangBasic
clangDriver
Expand Down
4 changes: 3 additions & 1 deletion flang/lib/FrontendTool/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ add_flang_library(flangFrontendTool

LINK_LIBS
flangFrontend
MLIRPass

LINK_COMPONENTS
Option
Support

MLIR_LIBS
MLIRPass

CLANG_LIBS
clangBasic
clangDriver
Expand Down
12 changes: 7 additions & 5 deletions flang/lib/Lower/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,19 @@ add_flang_library(FortranLower
FIRSupport
FIRTransforms
HLFIRDialect
${dialect_libs}
${extension_libs}
FortranCommon
FortranParser
FortranEvaluate
FortranSemantics

LINK_COMPONENTS
Support

MLIR_LIBS
${dialect_libs}
${extension_libs}
MLIRAffineToStandard
MLIRFuncDialect
MLIRLLVMDialect
MLIRSCFToControlFlow

LINK_COMPONENTS
Support
)
2 changes: 2 additions & 0 deletions flang/lib/Optimizer/Analysis/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ add_flang_library(FIRAnalysis
FIRBuilder
FIRDialect
HLFIRDialect

MLIR_LIBS
MLIRFuncDialect
MLIRLLVMDialect
MLIRMathTransforms
Expand Down
2 changes: 2 additions & 0 deletions flang/lib/Optimizer/Builder/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ add_flang_library(FIRBuilder
FIRSupport
FortranEvaluate
HLFIRDialect

MLIR_LIBS
${dialect_libs}
${extension_libs}
)
14 changes: 8 additions & 6 deletions flang/lib/Optimizer/CodeGen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ add_flang_library(FIRCodeGen
FIRDialect
FIRDialectSupport
FIRSupport

LINK_COMPONENTS
AsmParser
AsmPrinter
Remarks
TargetParser

MLIR_LIBS
MLIRComplexToLLVM
MLIRComplexToStandard
MLIRGPUDialect
Expand All @@ -34,10 +42,4 @@ add_flang_library(FIRCodeGen
MLIRLLVMToLLVMIRTranslation
MLIRTargetLLVMIRExport
MLIRVectorToLLVM

LINK_COMPONENTS
AsmParser
AsmPrinter
Remarks
TargetParser
)
12 changes: 7 additions & 5 deletions flang/lib/Optimizer/Dialect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ add_flang_library(FIRDialect
LINK_LIBS
CUFAttrs
FIRDialectSupport
MLIRArithDialect
MLIRBuiltinToLLVMIRTranslation
MLIROpenMPToLLVM
MLIRLLVMToLLVMIRTranslation
MLIRTargetLLVMIRExport

LINK_COMPONENTS
AsmParser
AsmPrinter
Remarks

MLIR_LIBS
MLIRArithDialect
MLIRBuiltinToLLVMIRTranslation
MLIROpenMPToLLVM
MLIRLLVMToLLVMIRTranslation
MLIRTargetLLVMIRExport
)
6 changes: 3 additions & 3 deletions flang/lib/Optimizer/Dialect/CUF/Attributes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ add_flang_library(CUFAttrs
CUFAttrsIncGen
CUFOpsIncGen

LINK_LIBS
MLIRTargetLLVMIRExport

LINK_COMPONENTS
AsmParser
AsmPrinter
Remarks

MLIR_LIBS
MLIRTargetLLVMIRExport
)
8 changes: 5 additions & 3 deletions flang/lib/Optimizer/Dialect/CUF/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ add_flang_library(CUFDialect
CUFAttrs
FIRDialect
FIRDialectSupport
MLIRIR
MLIRGPUDialect
MLIRTargetLLVMIRExport

LINK_COMPONENTS
AsmParser
AsmPrinter
Remarks

MLIR_LIBS
MLIRIR
MLIRGPUDialect
MLIRTargetLLVMIRExport
)
2 changes: 1 addition & 1 deletion flang/lib/Optimizer/Dialect/Support/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ add_flang_library(FIRDialectSupport
MLIRIR
intrinsics_gen

LINK_LIBS
MLIR_LIBS
${dialect_libs}
)
6 changes: 4 additions & 2 deletions flang/lib/Optimizer/HLFIR/IR/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ add_flang_library(HLFIRDialect
LINK_LIBS
CUFAttrs
FIRDialect
MLIRIR
${dialect_libs}

LINK_COMPONENTS
AsmParser
AsmPrinter
Remarks

MLIR_LIBS
MLIRIR
${dialect_libs}
)
6 changes: 4 additions & 2 deletions flang/lib/Optimizer/HLFIR/Transforms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ add_flang_library(HLFIRTransforms
FIRTransforms
FlangOpenMPTransforms
HLFIRDialect
MLIRIR
${dialect_libs}

LINK_COMPONENTS
AsmParser
AsmPrinter
Remarks

MLIR_LIBS
MLIRIR
${dialect_libs}
)
2 changes: 2 additions & 0 deletions flang/lib/Optimizer/OpenACC/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ add_flang_library(FIROpenACCSupport
FIRDialectSupport
FIRSupport
HLFIRDialect

MLIR_LIBS
MLIROpenACCDialect
)
4 changes: 3 additions & 1 deletion flang/lib/Optimizer/OpenMP/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ add_flang_library(FlangOpenMPTransforms
FIRSupport
FortranCommon
FortranEvaluate
HLFIRDialect

MLIR_LIBS
MLIRFuncDialect
MLIROpenMPDialect
HLFIRDialect
MLIRIR
MLIRPass
MLIRTransformUtils
Expand Down
12 changes: 7 additions & 5 deletions flang/lib/Optimizer/Passes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@ add_flang_library(flangPasses
FIRCodeGen
FIRTransforms
FlangOpenMPTransforms
${dialect_libs}
${extension_libs}
FortranCommon
HLFIRTransforms

LINK_COMPONENTS
Passes

MLIR_LIBS
${dialect_libs}
${extension_libs}
MLIRPass
MLIRReconcileUnrealizedCasts
MLIRSCFToControlFlow
MLIRSupport
MLIRTransforms

LINK_COMPONENTS
Passes
)
8 changes: 5 additions & 3 deletions flang/lib/Optimizer/Support/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ add_flang_library(FIRSupport

LINK_LIBS
FIRDialect

LINK_COMPONENTS
TargetParser

MLIR_LIBS
${dialect_libs}
${extension_libs}
MLIRBuiltinToLLVMIRTranslation
Expand All @@ -24,7 +29,4 @@ add_flang_library(FIRSupport
MLIRLLVMToLLVMIRTranslation
MLIRTargetLLVMIRExport
MLIRTargetLLVMIRImport

LINK_COMPONENTS
TargetParser
)
2 changes: 2 additions & 0 deletions flang/lib/Optimizer/Transforms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ add_flang_library(FIRTransforms
FIRSupport
FortranCommon
HLFIRDialect

MLIR_LIBS
MLIRAffineUtils
MLIRFuncDialect
MLIRGPUDialect
Expand Down
6 changes: 3 additions & 3 deletions flang/lib/Support/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
add_flang_library(FortranSupport
Timing.cpp

LINK_LIBS
MLIRSupport

LINK_COMPONENTS
Support

MLIR_LIBS
MLIRSupport
)
6 changes: 4 additions & 2 deletions flang/test/lib/Analysis/AliasAnalysis/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ add_flang_library(FIRTestAnalysis
FIRSupport
FIRTransforms
FIRAnalysis
MLIRTestAnalysis

MLIR_LIBS
${dialect_libs}
MLIRFuncDialect
MLIRLLVMDialect
MLIRAnalysis
MLIRTestAnalysis
)

target_include_directories(FIRTestAnalysis
PRIVATE
${MLIR_MAIN_SRC_DIR}/..
)
)
2 changes: 2 additions & 0 deletions flang/test/lib/OpenACC/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ add_flang_library(FIRTestOpenACCInterfaces
FIRDialect
FIROpenACCSupport
FIRSupport

MLIR_LIBS
MLIRIR
MLIROpenACCDialect
MLIRPass
Expand Down
3 changes: 3 additions & 0 deletions flang/tools/bbc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ target_link_libraries(bbc PRIVATE
flangFrontend
flangPasses
FlangOpenMPTransforms
)

mlir_target_link_libraries(bbc PRIVATE
${dialect_libs}
${extension_libs}
MLIRAffineToStandard
Expand Down
4 changes: 3 additions & 1 deletion flang/tools/fir-lsp-server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ target_link_libraries(fir-lsp-server PRIVATE
CUFDialect
FIRDialect
FIROpenACCSupport
HLFIRDialect
HLFIRDialect)

mlir_target_link_libraries(fir-lsp-server PRIVATE
MLIRLspServerLib
${dialect_libs}
${extension_libs})
3 changes: 3 additions & 0 deletions flang/tools/fir-opt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ target_link_libraries(fir-opt PRIVATE
FlangOpenMPTransforms
FIRAnalysis
${test_libs}
)

mlir_target_link_libraries(fir-opt PRIVATE
${dialect_libs}
${extension_libs}

Expand Down
3 changes: 3 additions & 0 deletions flang/tools/tco/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ target_link_libraries(tco PRIVATE
FIROpenACCSupport
FlangOpenMPTransforms
FortranCommon
)

mlir_target_link_libraries(tco PRIVATE
${dialect_libs}
${extension_libs}
MLIRIR
Expand Down
Loading

0 comments on commit 8d56cac

Please sign in to comment.