Skip to content

Commit 137a935

Browse files
committed
remove blocklist
Signed-off-by: Luca Mondada <luca@mondada.net>
1 parent 87bf748 commit 137a935

6 files changed

Lines changed: 22 additions & 68 deletions

File tree

cudaq/lib/Optimizer/CAPI/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# the terms of the Apache License 2.0 which accompanies this distribution. #
77
# ============================================================================ #
88

9-
add_mlir_public_c_api_library(CUDAQuantumMLIRCAPI
9+
add_mlir_public_c_api_library(cudaqDialectsCAPI
1010
Dialects.cpp
1111

1212
DEPENDS

cudaq/lib/Optimizer/README.md

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,14 @@ CUDAQ defines as one shared `mondo` library. The goal is twofold:
1414

1515
## Build strategy
1616

17-
The `libcudaqMLIR` library can be thought of as having three layers:
17+
The `libcudaqMLIR` library is built in two layers:
1818

19-
1. First, all object files from CUDAQ MLIR libraries (registered with `register_cudaq_mlir_lib`)
19+
1. All object files from CUDAQ MLIR libraries (registered with `register_cudaq_mlir_lib`)
2020
are bundled together in the shared library.
21-
2. Next, all MLIR targets listed in [`mlir-libs-allowlist.txt`](mlir-libs-allowlist.txt)
21+
2. All MLIR targets listed in [`mlir-libs-allowlist.txt`](mlir-libs-allowlist.txt)
2222
are added as static dependencies. By using CMake's `WHOLE_ARCHIVE` flag, we
2323
ensure that all symbols from these libraries are re-exported, so that CUDAQ libraries
2424
as well as downstream extensions can use them.
25-
3. Finally, we reduce the surface area of the shared library by hiding symbols
26-
from the block-list [`mlir-symbols-blocklist.txt`](mlir-symbols-blocklist.txt).
27-
This list contains symbols that are both unused by CUDAQ and (we estimate)
28-
are unlikely to become useful in the future for either CUDAQ or downstream extensions.
29-
30-
This somewhat complex setup allows us to ship as much as needed but as little as
31-
possible of MLIR. If at any point, symbols from MLIR are needed that are either
32-
not within the allow-listed MLIR components or are hidden by the block-list, we
33-
can adjust these lists accordingly.
3425

3526
## Adding a new library
3627

@@ -42,5 +33,4 @@ register_cudaq_mlir_lib(MyNewLib)
4233
```
4334

4435
If the library needs additional upstream MLIR symbols, add the corresponding `MLIR*`
45-
target to `mlir-libs-allowlist.txt` and ensure the required symbols are not hidden
46-
by the block-list.
36+
target to `mlir-libs-allowlist.txt`.

cudaq/lib/Optimizer/cudaqmlir-shlib.cmake

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# - All the object files of the libraries registered via register_cudaq_mlir_lib
1414
# - All the MLIR libraries listed in mlir-libs-allowlist.txt
1515
#
16-
# We mark the MLIR libraries as WHOLE_ARCHIVE dependencies so their full symbol set is
16+
# MLIR libraries are linked as WHOLE_ARCHIVE so their full symbol set is
1717
# exported for downstream plugins.
1818
################################################################################
1919

@@ -57,10 +57,13 @@ add_library(${LIBRARY_NAME} SHARED ${_cudaq_bundle_objs})
5757
# 2. Pull in the dependencies
5858
target_link_libraries(${LIBRARY_NAME} PRIVATE ${_cudaq_bundle_libs})
5959

60-
# 3. WHOLE_ARCHIVE the allowlisted MLIR libraries so their full symbol set is
61-
# exported for downstream plugins.
60+
# 3. WHOLE_ARCHIVE the allowlisted MLIR libraries and C-API dependencies so their
61+
# full symbol set is exported for downstream plugins.
6262
cudaq_read_symbol_list(
6363
"${CMAKE_CURRENT_SOURCE_DIR}/mlir-libs-allowlist.txt" _cudaq_mlir_whole_archive)
64+
get_property(_cudaq_required_mlir_libs GLOBAL PROPERTY CUDAQ_MLIR_REQUIRED_LIBS)
65+
list(APPEND _cudaq_mlir_whole_archive ${_cudaq_required_mlir_libs})
66+
list(REMOVE_DUPLICATES _cudaq_mlir_whole_archive)
6467
foreach(_lib IN LISTS _cudaq_mlir_whole_archive)
6568
if(TARGET ${_lib})
6669
target_link_libraries(${LIBRARY_NAME} PRIVATE "$<LINK_LIBRARY:WHOLE_ARCHIVE,${_lib}>")
@@ -70,31 +73,13 @@ foreach(_lib IN LISTS _cudaq_mlir_whole_archive)
7073
endif()
7174
endforeach()
7275

73-
# 4. Hide all symbols from the blocklist.
74-
cudaq_read_symbol_list(
75-
"${CMAKE_CURRENT_SOURCE_DIR}/mlir-symbols-blocklist.txt" _cudaq_blocklist_patterns)
76-
if(APPLE)
77-
# ld64: one glob per line; localize via -unexported_symbols_list.
78-
set(_cudaq_symbol_list "${CMAKE_CURRENT_BINARY_DIR}/cudaqMLIR-unexported.txt")
79-
# relink if the symbol list changes
80-
set_property(TARGET ${LIBRARY_NAME} APPEND PROPERTY LINK_DEPENDS "${_cudaq_symbol_list}")
81-
string(REPLACE ";" "\n" _cudaq_unexported "${_cudaq_blocklist_patterns}")
82-
file(WRITE "${_cudaq_symbol_list}" "${_cudaq_unexported}\n")
83-
target_link_options(${LIBRARY_NAME} PRIVATE
84-
"LINKER:-unexported_symbols_list,${_cudaq_symbol_list}")
85-
else()
86-
# GNU ld / lld: a version script with a local: block leaves the rest exported.
87-
set(_cudaq_version_script "${CMAKE_CURRENT_BINARY_DIR}/cudaqMLIR-hidden.map")
88-
# relink if the version script changes
89-
set_property(TARGET ${LIBRARY_NAME} APPEND PROPERTY LINK_DEPENDS "${_cudaq_version_script}")
90-
set(_cudaq_blocklist_body "")
91-
foreach(_pat IN LISTS _cudaq_blocklist_patterns)
92-
string(APPEND _cudaq_blocklist_body " ${_pat};\n")
93-
endforeach()
94-
file(WRITE "${_cudaq_version_script}" "{\n local:\n${_cudaq_blocklist_body}};\n")
95-
target_link_options(${LIBRARY_NAME} PRIVATE
96-
"LINKER:--version-script=${_cudaq_version_script}")
97-
endif()
76+
# 4. Bundle the LLVM native target for JITing.
77+
llvm_map_components_to_libnames(_cudaq_llvm_native_libs native nativecodegen)
78+
foreach(_lib IN LISTS _cudaq_llvm_native_libs)
79+
if(TARGET ${_lib})
80+
target_link_libraries(${LIBRARY_NAME} PRIVATE "$<LINK_LIBRARY:WHOLE_ARCHIVE,${_lib}>")
81+
endif()
82+
endforeach()
9883

9984
# We are using the following linker flags:
10085
# - -Bsymbolic-functions: ELF treats symbols as preemptible by default. This adds a
@@ -112,5 +97,5 @@ else()
11297
target_link_options(${LIBRARY_NAME} PRIVATE "LINKER:--gc-sections")
11398
endif()
11499

115-
install(TARGETS ${LIBRARY_NAME} EXPORT CUDAQTargets DESTINATION lib)
100+
install(TARGETS ${LIBRARY_NAME} EXPORT cudaq-targets DESTINATION lib)
116101
set_target_properties(${LIBRARY_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)

cudaq/lib/Optimizer/mlir-libs-allowlist.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# the terms of the Apache License 2.0 which accompanies this distribution. #
77
# ============================================================================ #
88

9-
# Whitelist of MLIR libraries that cudaqMLIR whole-archives and downstream
9+
# Allowlist of MLIR libraries that cudaqMLIR whole-archives and downstream
1010
# plugins can link against.
1111

1212
# Core IR + support

cudaq/lib/Optimizer/mlir-symbols-blocklist.txt

Lines changed: 0 additions & 21 deletions
This file was deleted.

python/extension/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ declare_mlir_python_extension(CUDAQuantumPythonSources.SiteInitialize
6262
SOURCES
6363
SiteInitialize.cpp
6464
EMBED_CAPI_LINK_LIBS
65-
CUDAQuantumMLIRCAPI
65+
cudaqDialectsCAPI
6666
)
6767

6868
if(APPLE)
@@ -161,7 +161,7 @@ declare_mlir_python_extension(CUDAQuantumPythonSources.Extension
161161
../../runtime/internal/compiler/RuntimePyMLIR.cpp
162162

163163
EMBED_CAPI_LINK_LIBS
164-
CUDAQuantumMLIRCAPI
164+
cudaqDialectsCAPI
165165
MLIRCAPIExecutionEngine
166166
PRIVATE_LINK_LIBS
167167
${_quakeDialects_pipeline_carrying_link_libs}

0 commit comments

Comments
 (0)