@@ -16,23 +16,10 @@ if (LLVM_DIR)
16
16
# Builds that use pre-installed LLVM have LLVM_DIR set.
17
17
# A standalone or LLVM_ENABLE_RUNTIMES=openmp build takes this route
18
18
find_program (CLANG_TOOL clang PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH)
19
- find_program (PACKAGER_TOOL clang-offload-packager PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH)
20
- find_program (LINK_TOOL llvm-link PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH)
21
- find_program (OPT_TOOL opt PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH)
22
- if ((NOT CLANG_TOOL) OR (NOT LINK_TOOL) OR (NOT OPT_TOOL) OR (NOT PACKAGER_TOOL))
23
- message (STATUS "Not building DeviceRTL. Missing clang: ${CLANG_TOOL} , llvm-link: ${LINK_TOOL} , opt: ${OPT_TOOL} , or clang-offload-packager: ${PACKAGER_TOOL} " )
24
- return ()
25
- else ()
26
- message (STATUS "Building DeviceRTL. Using clang: ${CLANG_TOOL} , llvm-link: ${LINK_TOOL} and opt: ${OPT_TOOL} " )
27
- endif ()
28
19
elseif (LLVM_TOOL_CLANG_BUILD AND NOT CMAKE_CROSSCOMPILING AND NOT OPENMP_STANDALONE_BUILD)
29
20
# LLVM in-tree builds may use CMake target names to discover the tools.
30
21
# A LLVM_ENABLE_PROJECTS=openmp build takes this route
31
22
set (CLANG_TOOL $<TARGET_FILE:clang>)
32
- set (PACKAGER_TOOL $<TARGET_FILE:clang-offload-packager>)
33
- set (LINK_TOOL $<TARGET_FILE:llvm-link>)
34
- set (OPT_TOOL $<TARGET_FILE:opt>)
35
- message (STATUS "Building DeviceRTL. Using clang from in-tree build" )
36
23
else ()
37
24
message (STATUS "Not building DeviceRTL. No appropriate clang found" )
38
25
return ()
@@ -82,8 +69,6 @@ set(src_files
82
69
# propagation. That said, we will run the vectorizer again after the runtime
83
70
# has been linked into the user program.
84
71
set (clang_opt_flags -O3 -mllvm -openmp-opt-disable -DSHARED_SCRATCHPAD_SIZE=512 -mllvm -vectorize-slp=false )
85
- set (link_opt_flags -O3 -openmp-opt-disable -attributor-enable=module -vectorize-slp=false )
86
- set (link_export_flag -passes=internalize -internalize-public -api-file=${source_directory} /exports)
87
72
88
73
# If the user built with the GPU C library enabled we will use that instead.
89
74
if (${LIBOMPTARGET_GPU_LIBC_SUPPORT} )
@@ -107,15 +92,13 @@ set(bc_flags -c -flto -std=c++17 -fvisibility=hidden
107
92
)
108
93
109
94
# first create an object target
110
- add_library (omptarget.devicertl.all_objs OBJECT IMPORTED )
111
95
function (compileDeviceRTLLibrary target_name target_triple)
112
96
set (target_bc_flags ${ARGN} )
113
97
114
- set (bc_files "" )
115
98
foreach (src ${src_files} )
116
99
get_filename_component (infile ${src} ABSOLUTE )
117
100
get_filename_component (outfile ${src} NAME )
118
- set (outfile "${outfile} -${target_name} .bc " )
101
+ set (outfile "${outfile} -${target_name} .o " )
119
102
set (depfile "${outfile} .d" )
120
103
121
104
# Passing an empty CPU to -march= suppressed target specific metadata.
@@ -142,99 +125,40 @@ function(compileDeviceRTLLibrary target_name target_triple)
142
125
endif ()
143
126
set_property (DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${outfile} )
144
127
145
- list (APPEND bc_files ${outfile} )
128
+ list (APPEND obj_files ${CMAKE_CURRENT_BINARY_DIR} / ${outfile} )
146
129
endforeach ()
147
-
148
- set (bclib_name "libomptarget-${target_name} .bc" )
149
-
150
- # Link to a bitcode library.
151
- add_custom_command (OUTPUT ${CMAKE_CURRENT_BINARY_DIR} /linked_${bclib_name}
152
- COMMAND ${LINK_TOOL}
153
- -o ${CMAKE_CURRENT_BINARY_DIR} /linked_${bclib_name} ${bc_files}
154
- DEPENDS ${bc_files}
155
- COMMENT "Linking LLVM bitcode ${bclib_name} "
156
- )
157
-
158
- if (TARGET llvm-link)
159
- add_custom_command (OUTPUT ${CMAKE_CURRENT_BINARY_DIR} /linked_${bclib_name}
160
- DEPENDS llvm-link
161
- APPEND )
162
- endif ()
163
-
164
- add_custom_command (OUTPUT ${CMAKE_CURRENT_BINARY_DIR} /internalized_${bclib_name}
165
- COMMAND ${OPT_TOOL} ${link_export_flag} ${CMAKE_CURRENT_BINARY_DIR} /linked_${bclib_name}
166
- -o ${CMAKE_CURRENT_BINARY_DIR} /internalized_${bclib_name}
167
- DEPENDS ${source_directory} /exports ${CMAKE_CURRENT_BINARY_DIR} /linked_${bclib_name}
168
- COMMENT "Internalizing LLVM bitcode ${bclib_name} "
169
- )
170
- if (TARGET opt)
171
- add_custom_command (OUTPUT ${CMAKE_CURRENT_BINARY_DIR} /internalized_${bclib_name}
172
- DEPENDS opt
173
- APPEND )
174
- endif ()
175
-
176
- add_custom_command (OUTPUT ${CMAKE_CURRENT_BINARY_DIR} /${bclib_name}
177
- COMMAND ${OPT_TOOL} ${link_opt_flags} ${CMAKE_CURRENT_BINARY_DIR} /internalized_${bclib_name}
178
- -o ${CMAKE_CURRENT_BINARY_DIR} /${bclib_name}
179
- DEPENDS ${CMAKE_CURRENT_BINARY_DIR} /internalized_${bclib_name}
180
- COMMENT "Optimizing LLVM bitcode ${bclib_name} "
181
- )
182
- if (TARGET opt)
183
- add_custom_command (OUTPUT ${CMAKE_CURRENT_BINARY_DIR} /${bclib_name}
184
- DEPENDS opt
185
- APPEND )
186
- endif ()
187
-
188
- set (bclib_target_name "omptarget-${target_name} -bc" )
189
- add_custom_target (${bclib_target_name} DEPENDS ${CMAKE_CURRENT_BINARY_DIR} /${bclib_name} )
190
-
191
- # Copy library to destination.
192
- add_custom_command (TARGET ${bclib_target_name} POST_BUILD
193
- COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR} /${bclib_name}
194
- ${LIBOMPTARGET_LIBRARY_DIR} )
195
- add_dependencies (omptarget.devicertl.${target_name} ${bclib_target_name} )
196
-
197
- set_property (DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${bclib_name} ${LIBOMPTARGET_LIBRARY_DIR} /${bclib_name} )
198
-
199
- # Install bitcode library under the lib destination folder.
200
- install (FILES ${CMAKE_CURRENT_BINARY_DIR} /${bclib_name} DESTINATION "${OFFLOAD_INSTALL_LIBDIR} " )
201
-
202
- set (target_feature "" )
203
- if ("${target_triple} " STREQUAL "nvptx64-nvidia-cuda" )
204
- set (target_feature "feature=+ptx63" )
205
- endif ()
206
-
207
- # Package the bitcode in the bitcode and embed it in an ELF for the static library
208
- add_custom_command (OUTPUT ${CMAKE_CURRENT_BINARY_DIR} /packaged_${bclib_name}
209
- COMMAND ${PACKAGER_TOOL} -o ${CMAKE_CURRENT_BINARY_DIR} /packaged_${bclib_name}
210
- "--image=file=${CMAKE_CURRENT_BINARY_DIR} /${bclib_name} ,${target_feature} ,triple=${target_triple} ,arch=generic,kind=openmp"
211
- DEPENDS ${CMAKE_CURRENT_BINARY_DIR} /${bclib_name}
212
- COMMENT "Packaging LLVM offloading binary ${bclib_name} .out"
213
- )
214
- if (TARGET clang-offload-packager)
215
- add_custom_command (OUTPUT ${CMAKE_CURRENT_BINARY_DIR} /packaged_${bclib_name}
216
- DEPENDS clang-offload-packager
217
- APPEND )
218
- endif ()
219
-
220
- set (output_name "${CMAKE_CURRENT_BINARY_DIR} /devicertl-${target_name} .o" )
221
- add_custom_command (OUTPUT ${output_name}
222
- COMMAND ${CLANG_TOOL} --std=c++17 -c -nostdlib
223
- -Xclang -fembed-offload-object=${CMAKE_CURRENT_BINARY_DIR} /packaged_${bclib_name}
224
- -o ${output_name}
225
- ${source_directory} /Stub.cpp
226
- DEPENDS ${CMAKE_CURRENT_BINARY_DIR} /packaged_${bclib_name} ${source_directory} /Stub.cpp
227
- COMMENT "Embedding LLVM offloading binary in devicertl-${target_name} .o"
228
- VERBATIM
130
+ # Trick to combine these into a bitcode file via the linker's LTO pass. This
131
+ # is used to provide the legacy `libomptarget-<name>.bc` files. Hack this
132
+ # through as an executable to get it to use the relocatable link.
133
+ add_executable (libomptarget-${target_name} ${obj_files} )
134
+ set_target_properties (libomptarget-${target_name} PROPERTIES
135
+ RUNTIME_OUTPUT_DIRECTORY ${LIBOMPTARGET_LLVM_LIBRARY_INTDIR}
136
+ LINKER_LANGUAGE CXX
137
+ BUILD_RPATH ""
138
+ INSTALL_RPATH ""
139
+ RUNTIME_OUTPUT_NAME libomptarget-${target_name} .bc)
140
+ target_compile_options (libomptarget-${target_name} PRIVATE "--target=${target_triple} " )
141
+ target_link_options (libomptarget-${target_name} PRIVATE "--target=${target_triple} "
142
+ "-r" "-nostdlib" "-flto" "-Wl,--lto-emit-llvm" )
143
+ install (TARGETS libomptarget-${target_name}
144
+ PERMISSIONS OWNER_WRITE OWNER_READ GROUP_READ WORLD_READ
145
+ DESTINATION ${OFFLOAD_INSTALL_LIBDIR} )
146
+
147
+ add_library (omptarget.${target_name} .all_objs OBJECT IMPORTED )
148
+ set_property (TARGET omptarget.${target_name} .all_objs APPEND PROPERTY IMPORTED_OBJECTS
149
+ ${LIBOMPTARGET_LLVM_LIBRARY_INTDIR} /libomptarget-${target_name} .bc)
150
+
151
+ # Archive all the object files generated above into a static library
152
+ add_library (omptarget.${target_name} STATIC )
153
+ set_target_properties (omptarget.${target_name} PROPERTIES
154
+ ARCHIVE_OUTPUT_DIRECTORY "${LIBOMPTARGET_LLVM_LIBRARY_INTDIR} /${target_triple} "
155
+ ARCHIVE_OUTPUT_NAME ompdevice
156
+ LINKER_LANGUAGE CXX
229
157
)
230
- if (TARGET clang)
231
- add_custom_command (OUTPUT ${output_name}
232
- DEPENDS clang
233
- APPEND )
234
- endif ()
158
+ target_link_libraries (omptarget.${target_name} PRIVATE omptarget.${target_name} .all_objs)
235
159
236
- set_property ( DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${output_name} )
237
- set_property ( TARGET omptarget.devicertl.all_objs APPEND PROPERTY IMPORTED_OBJECTS ${output_name} )
160
+ install (TARGETS omptarget. ${target_name}
161
+ ARCHIVE DESTINATION "lib ${LLVM_LIBDIR_SUFFIX} / ${target_triple} " )
238
162
239
163
if (CMAKE_EXPORT_COMPILE_COMMANDS)
240
164
set (ide_target_name omptarget-ide-${target_name} )
@@ -254,18 +178,10 @@ function(compileDeviceRTLLibrary target_name target_triple)
254
178
endif ()
255
179
endfunction ()
256
180
257
- add_custom_target (omptarget.devicertl.amdgpu)
258
- compileDeviceRTLLibrary(amdgpu amdgcn-amd-amdhsa -Xclang -mcode-object-version =none)
259
-
260
- add_custom_target (omptarget.devicertl.nvptx)
261
- compileDeviceRTLLibrary(nvptx nvptx64-nvidia-cuda --cuda-feature=+ptx63)
262
-
263
- # Archive all the object files generated above into a static library
264
- add_library (omptarget.devicertl STATIC )
265
- set_target_properties (omptarget.devicertl PROPERTIES
266
- ARCHIVE_OUTPUT_DIRECTORY "${LIBOMPTARGET_LLVM_LIBRARY_INTDIR} "
267
- LINKER_LANGUAGE CXX
268
- )
269
- target_link_libraries (omptarget.devicertl PRIVATE omptarget.devicertl.all_objs)
181
+ if (NOT LLVM_TARGETS_TO_BUILD OR "AMDGPU" IN_LIST LLVM_TARGETS_TO_BUILD)
182
+ compileDeviceRTLLibrary(amdgpu amdgcn-amd-amdhsa -Xclang -mcode-object-version =none)
183
+ endif ()
270
184
271
- install (TARGETS omptarget.devicertl ARCHIVE DESTINATION ${OFFLOAD_INSTALL_LIBDIR} )
185
+ if (NOT LLVM_TARGETS_TO_BUILD OR "NVPTX" IN_LIST LLVM_TARGETS_TO_BUILD)
186
+ compileDeviceRTLLibrary(nvptx nvptx64-nvidia-cuda --cuda-feature=+ptx63)
187
+ endif ()
0 commit comments