@@ -89,7 +89,7 @@ endfunction()
89
89
# add_gpu_entrypoint_library(
90
90
# DEPENDS <list of add_entrypoint_object targets>
91
91
# )
92
- function (add_gpu_entrypoint_library target_name )
92
+ function (add_gpu_entrypoint_library target_name base_target_name )
93
93
cmake_parse_arguments (
94
94
"ENTRYPOINT_LIBRARY"
95
95
"" # No optional arguments
@@ -127,7 +127,7 @@ function(add_gpu_entrypoint_library target_name)
127
127
COMMAND ${LIBC_CLANG_OFFLOAD_PACKAGER}
128
128
"${prefix} ,file=$<JOIN:${object} ,,file=>" -o
129
129
${CMAKE_CURRENT_BINARY_DIR} /binary/${name}.gpubin
130
- DEPENDS ${dep}
130
+ DEPENDS ${dep} ${base_target_name}
131
131
COMMENT "Packaging LLVM offloading binary for '${object} '"
132
132
)
133
133
add_custom_target (${dep} .__gpubin__ DEPENDS ${dep}
@@ -140,7 +140,7 @@ function(add_gpu_entrypoint_library target_name)
140
140
OUTPUT "${CMAKE_CURRENT_BINARY_DIR} /stubs/${name} .cpp"
141
141
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR} /stubs
142
142
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR} /stubs/${name}.cpp
143
- DEPENDS ${dep} ${dep} .__gpubin__
143
+ DEPENDS ${dep} ${dep} .__gpubin__ ${base_target_name}
144
144
)
145
145
add_custom_target (${dep} .__stub__
146
146
DEPENDS ${dep} .__gpubin__ "${CMAKE_CURRENT_BINARY_DIR} /stubs/${name} .cpp" )
@@ -156,7 +156,8 @@ function(add_gpu_entrypoint_library target_name)
156
156
target_compile_options (${dep} .__fatbin__ PRIVATE
157
157
--target=${LLVM_HOST_TRIPLE}
158
158
"SHELL:-Xclang -fembed-offload-object=${CMAKE_CURRENT_BINARY_DIR} /binary/${name} .gpubin" )
159
- add_dependencies (${dep} .__fatbin__ ${dep} ${dep} .__stub__ ${dep} .__gpubin__ )
159
+ add_dependencies (${dep} .__fatbin__
160
+ ${dep} ${dep} .__stub__ ${dep} .__gpubin__ ${base_target_name} )
160
161
161
162
# Set the list of newly create fat binaries containing embedded device code.
162
163
list (APPEND objects $< TARGET_OBJECTS:${dep} .__fatbin__> )
@@ -170,6 +171,46 @@ function(add_gpu_entrypoint_library target_name)
170
171
set_target_properties (${target_name} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${LIBC_LIBRARY_DIR} )
171
172
endfunction (add_gpu_entrypoint_library )
172
173
174
+ # A rule to build a library from a collection of entrypoint objects and bundle
175
+ # it in a single LLVM-IR bitcode file.
176
+ # Usage:
177
+ # add_gpu_entrypoint_library(
178
+ # DEPENDS <list of add_entrypoint_object targets>
179
+ # )
180
+ function (add_bitcode_entrypoint_library target_name base_target_name )
181
+ cmake_parse_arguments (
182
+ "ENTRYPOINT_LIBRARY"
183
+ "" # No optional arguments
184
+ "" # No single value arguments
185
+ "DEPENDS" # Multi-value arguments
186
+ ${ARGN}
187
+ )
188
+ if (NOT ENTRYPOINT_LIBRARY_DEPENDS )
189
+ message (FATAL_ERROR "'add_entrypoint_library' target requires a DEPENDS list "
190
+ "of 'add_entrypoint_object' targets." )
191
+ endif ()
192
+
193
+ get_fq_deps_list (fq_deps_list ${ENTRYPOINT_LIBRARY_DEPENDS} )
194
+ get_all_object_file_deps (all_deps "${fq_deps_list} " )
195
+
196
+ set (objects "" )
197
+ foreach (dep IN LISTS all_deps )
198
+ set (object $< $< STREQUAL:$< TARGET_NAME_IF_EXISTS:${dep} > ,${dep} > :$< TARGET_OBJECTS:${dep} > > )
199
+ list (APPEND objects ${object} )
200
+ endforeach ()
201
+
202
+ set (output ${CMAKE_CURRENT_BINARY_DIR} /${target_name}.bc )
203
+ add_custom_command (
204
+ OUTPUT ${output}
205
+ COMMAND ${LIBC_LLVM_LINK} ${objects} -o ${output}
206
+ DEPENDS ${all_deps} ${base_target_name}
207
+ COMMENT "Linking LLVM-IR bitcode for ${base_target_name} "
208
+ COMMAND_EXPAND_LISTS
209
+ )
210
+ add_custom_target (${target_name} DEPENDS ${output} ${all_deps} )
211
+ set_target_properties (${target_name} PROPERTIES TARGET_OBJECT ${output} )
212
+ endfunction (add_bitcode_entrypoint_library )
213
+
173
214
# A rule to build a library from a collection of entrypoint objects.
174
215
# Usage:
175
216
# add_entrypoint_library(
0 commit comments