[llvm] [mlir] CMake: Remove unnecessary dependencies on LLVM/MLIR (PR #110362)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 28 08:31:18 PDT 2024
Adnios wrote:
Thanks for catching.
> how did you identify these? Manually or automatically?
Firstly I follow [this blog](https://cristianadam.eu/20190501/bundling-together-static-libraries-with-cmake/) to recursively collect MLIR/LLVM related dependencies for our own library (libMy.a) or binary (MyBinary). (And print the dependencies tree for better visualization)
E.g:
```
....
| | | | | | |--MLIRArithDialect(depth:6, dep_count:8)
| | | | | | | |--MLIRCastInterfaces(depth:7, dep_count:2)
| | | | | | | |--MLIRDialect(depth:7, dep_count:2)
| | | | | | | |--MLIRInferIntRangeCommon(depth:7, dep_count:3)
| | | | | | | | |--MLIRInferIntRangeInterface(depth:8, dep_count:2)
| | | | | | | |--MLIRInferTypeOpInterface(depth:7, dep_count:2)
| | | | | | | |--MLIRUBDialect(depth:7, dep_count:2)
| | | | | |--MLIRLLVMDialect(depth:5, dep_count:15)
| | | | | | |--MLIRCallInterfaces(depth:6, dep_count:2)
| | | | | | |--MLIRControlFlowInterfaces(depth:6, dep_count:2)
| | | | | | |--MLIRDataLayoutInterfaces(depth:6, dep_count:2)
| | | | | | |--MLIRFunctionInterfaces(depth:6, dep_count:2)
| | | | | | |--MLIRMemorySlotInterfaces(depth:6, dep_count:2)
| | | | | | |--MLIRSideEffectInterfaces(depth:6, dep_count:2)
| | | | | | |--LLVMAsmParser(depth:6, dep_count:3)
| | | | | | | |--LLVMBinaryFormat(depth:7, dep_count:2)
| | | | | | | | |--LLVMTargetParser(depth:8, dep_count:1)
| | | | | | | |--LLVMCore(depth:7, dep_count:8)
| | | | | | | | |--LLVMRemarks(depth:8, dep_count:2)
...
```
Meanwhile, I also try dump the linker map of binary (MyBinary) by adding following code to CMakeLists.txt.
```
set(MyBinary_LINKER_MAP_FILE ${CMAKE_CURRENT_BINARY_DIR}/MyBinary.map)
target_link_options(MyBinary PRIVATE LINKER:-Map=${MyBinary_LINKER_MAP_FILE})
```
Then use regex to extract all libMLIR/LLVM*.a from MyBinary.map. By comparing these with the dependencies obtained from CMake functions and linker maps, I notice that the "linker map" method has fewer dependencies and eliminates unnecessary libraries.
Then I start manually remove this unneeded libraries in CMakeLists.txt and open this PR.
https://github.com/llvm/llvm-project/pull/110362
More information about the llvm-commits
mailing list