Skip to content

Commit 88dae3d

Browse files
authored
[OpenMP][libomp] Remove Perl in favor of Python (#95307)
* Removes all Perl scripts and modules * Adds Python3 scripts which mimic the behavior of the Perl scripts * Removes Perl from CMake; Adds Python3 requirement to CMake * The check-instruction-set.pl script is Knights Corner specific. The script is removed and not replicated with a corresponding Python3 script. Relevant Discourse: https://discourse.llvm.org/t/error-compiling-clang-with-offloading-support/79223/4 Fixes: #62289
1 parent 67da89c commit 88dae3d

20 files changed

+987
-5618
lines changed

openmp/runtime/cmake/LibompExports.cmake

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,22 @@ endif()
2828
string(REPLACE ";" "" libomp_suffix "${libomp_suffix}")
2929

3030
# Set exports locations
31+
if(WIN32)
32+
set(LIBOMP_SHORT_OS win)
33+
elseif(APPLE)
34+
set(LIBOMP_SHORT_OS mac)
35+
else()
36+
set(LIBOMP_SHORT_OS lin)
37+
endif()
3138
if(${MIC})
32-
set(libomp_platform "${LIBOMP_PERL_SCRIPT_OS}_${LIBOMP_MIC_ARCH}") # e.g., lin_knf, lin_knc
39+
set(libomp_platform "${LIBOMP_SHORT_OS}_${LIBOMP_MIC_ARCH}") # e.g., lin_knf, lin_knc
3340
else()
3441
if(${IA32})
35-
set(libomp_platform "${LIBOMP_PERL_SCRIPT_OS}_32")
42+
set(libomp_platform "${LIBOMP_SHORT_OS}_32")
3643
elseif(${INTEL64})
37-
set(libomp_platform "${LIBOMP_PERL_SCRIPT_OS}_32e")
44+
set(libomp_platform "${LIBOMP_SHORT_OS}_32e")
3845
else()
39-
set(libomp_platform "${LIBOMP_PERL_SCRIPT_OS}_${LIBOMP_ARCH}") # e.g., lin_arm, lin_ppc64
46+
set(libomp_platform "${LIBOMP_SHORT_OS}_${LIBOMP_ARCH}") # e.g., lin_arm, lin_ppc64
4047
endif()
4148
endif()
4249
set(LIBOMP_EXPORTS_DIR "${LIBOMP_BASE_DIR}/exports")

openmp/runtime/cmake/LibompHandleFlags.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ function(libomp_get_fflags fflags)
170170
set(${fflags} ${fflags_local} PARENT_SCOPE)
171171
endfunction()
172172

173-
# Perl generate-defs.pl flags (For Windows only)
173+
# Python generate-defs.py flags (For Windows only)
174174
function(libomp_get_gdflags gdflags)
175175
set(gdflags_local)
176176
if(${IA32})

openmp/runtime/cmake/LibompMicroTests.cmake

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,7 @@
2525
# - Fails if stack is executable. Should only be readable and writable. Not executable.
2626
# - Program dependencies: perl, readelf
2727
# - Available for Unix dynamic library builds. Not available otherwise.
28-
# (4) test-instr (Intel(R) MIC Architecture only)
29-
# - Tests Intel(R) MIC Architecture libraries for valid instruction set
30-
# - Fails if finds invalid instruction for Intel(R) MIC Architecture (wasn't compiled with correct flags)
31-
# - Program dependencies: perl, objdump
32-
# - Available for Intel(R) MIC Architecture and i386 builds. Not available otherwise.
33-
# (5) test-deps
28+
# (4) test-deps
3429
# - Tests newly created libomp for library dependencies
3530
# - Fails if sees a dependence not listed in td_exp variable below
3631
# - Program dependencies: perl, (unix)readelf, (mac)otool[64], (windows)link.exe
@@ -93,7 +88,6 @@ endif()
9388
macro(libomp_test_touch_recipe test_touch_dir)
9489
set(libomp_test_touch_dependencies ${LIBOMP_SRC_DIR}/test-touch.c omp)
9590
set(libomp_test_touch_exe ${test_touch_dir}/test-touch${CMAKE_EXECUTABLE_SUFFIX})
96-
set(libomp_test_touch_obj ${test_touch_dir}/test-touch${CMAKE_C_OUTPUT_EXTENSION})
9791
if(WIN32)
9892
if(${RELEASE_BUILD} OR ${RELWITHDEBINFO_BUILD})
9993
if(${test_touch_dir} MATCHES "test-touch-mt")
@@ -108,13 +102,13 @@ macro(libomp_test_touch_recipe test_touch_dir)
108102
libomp_append(libomp_test_touch_cflags /MDd)
109103
endif()
110104
endif()
111-
set(libomp_test_touch_out_flags -Fe${libomp_test_touch_exe} -Fo${libomp_test_touch_obj})
105+
set(libomp_test_touch_out_flags -Fe${libomp_test_touch_exe})
112106
list(APPEND libomp_test_touch_dependencies ompimp)
113107
else()
114108
set(libomp_test_touch_out_flags -o ${libomp_test_touch_exe})
115109
endif()
116110
add_custom_command(
117-
OUTPUT ${test_touch_dir}/.success ${libomp_test_touch_exe} ${libomp_test_touch_obj}
111+
OUTPUT ${test_touch_dir}/.success ${libomp_test_touch_exe}
118112
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/${test_touch_dir}
119113
COMMAND ${CMAKE_COMMAND} -E remove -f ${test_touch_dir}/*
120114
COMMAND ${libomp_test_touch_compiler} ${libomp_test_touch_out_flags} ${libomp_test_touch_cflags}
@@ -152,22 +146,10 @@ set_target_properties(libomp-test-execstack PROPERTIES FOLDER "OpenMP/Tests")
152146
add_custom_command(
153147
OUTPUT test-execstack/.success
154148
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/test-execstack
155-
COMMAND ${PERL_EXECUTABLE} ${LIBOMP_TOOLS_DIR}/check-execstack.pl
156-
--arch=${LIBOMP_PERL_SCRIPT_ARCH} ${LIBOMP_OUTPUT_DIRECTORY}/${LIBOMP_LIB_FILE}
149+
COMMAND ${Python3_EXECUTABLE} ${LIBOMP_TOOLS_DIR}/check-execstack.py
150+
${LIBOMP_OUTPUT_DIRECTORY}/${LIBOMP_LIB_FILE}
157151
COMMAND ${CMAKE_COMMAND} -E touch test-execstack/.success
158-
DEPENDS omp
159-
)
160-
161-
# test-instr
162-
add_custom_target(libomp-test-instr DEPENDS test-instr/.success)
163-
set_target_properties(libomp-test-instr PROPERTIES FOLDER "OpenMP/Tests")
164-
add_custom_command(
165-
OUTPUT test-instr/.success
166-
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/test-instr
167-
COMMAND ${PERL_EXECUTABLE} ${LIBOMP_TOOLS_DIR}/check-instruction-set.pl --os=${LIBOMP_PERL_SCRIPT_OS}
168-
--arch=${LIBOMP_PERL_SCRIPT_ARCH} --show --mic-arch=${LIBOMP_MIC_ARCH} ${LIBOMP_OUTPUT_DIRECTORY}/${LIBOMP_LIB_FILE}
169-
COMMAND ${CMAKE_COMMAND} -E touch test-instr/.success
170-
DEPENDS omp ${LIBOMP_TOOLS_DIR}/check-instruction-set.pl
152+
DEPENDS omp ${LIBOMP_TOOLS_DIR}/check-execstack.py
171153
)
172154
173155
# test-deps
@@ -187,7 +169,15 @@ elseif(APPLE)
187169
set(libomp_expected_library_deps /usr/lib/libSystem.B.dylib)
188170
elseif(WIN32)
189171
set(libomp_expected_library_deps kernel32.dll)
190-
libomp_append(libomp_expected_library_deps psapi.dll LIBOMP_OMPT_SUPPORT)
172+
libomp_append(libomp_expected_library_deps api-ms-win-crt-convert-l1-1-0.dll)
173+
libomp_append(libomp_expected_library_deps api-ms-win-crt-environment-l1-1-0.dll)
174+
libomp_append(libomp_expected_library_deps api-ms-win-crt-heap-l1-1-0.dll)
175+
libomp_append(libomp_expected_library_deps api-ms-win-crt-runtime-l1-1-0.dll)
176+
libomp_append(libomp_expected_library_deps api-ms-win-crt-stdio-l1-1-0.dll)
177+
libomp_append(libomp_expected_library_deps api-ms-win-crt-string-l1-1-0.dll)
178+
libomp_append(libomp_expected_library_deps api-ms-win-crt-utility-l1-1-0.dll)
179+
libomp_append(libomp_expected_library_deps vcruntime140.dll)
180+
libomp_append(libomp_expected_library_deps psapi.dll)
191181
else()
192182
if(${MIC})
193183
set(libomp_expected_library_deps libc.so.6 libpthread.so.0 libdl.so.2)
@@ -202,9 +192,11 @@ else()
202192
if(${IA32})
203193
libomp_append(libomp_expected_library_deps libc.so.6)
204194
libomp_append(libomp_expected_library_deps ld-linux.so.2)
195+
libomp_append(libomp_expected_library_deps librt.so.1)
205196
elseif(${INTEL64})
206197
libomp_append(libomp_expected_library_deps libc.so.6)
207198
libomp_append(libomp_expected_library_deps ld-linux-x86-64.so.2)
199+
libomp_append(libomp_expected_library_deps librt.so.1)
208200
elseif(${ARM})
209201
libomp_append(libomp_expected_library_deps libc.so.6)
210202
libomp_append(libomp_expected_library_deps libffi.so.6)
@@ -232,13 +224,14 @@ else()
232224
libomp_append(libomp_expected_library_deps libstdc++.so.6 LIBOMP_USE_STDCPPLIB)
233225
libomp_append(libomp_expected_library_deps libm.so.6 LIBOMP_STATS)
234226
endif()
235-
# Perl script expects comma separated list
227+
# Check depends script expects comma separated list
236228
string(REPLACE ";" "," libomp_expected_library_deps "${libomp_expected_library_deps}")
237229
add_custom_command(
238230
OUTPUT test-deps/.success
239231
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/test-deps
240-
COMMAND ${PERL_EXECUTABLE} ${LIBOMP_TOOLS_DIR}/check-depends.pl --os=${LIBOMP_PERL_SCRIPT_OS}
241-
--arch=${LIBOMP_PERL_SCRIPT_ARCH} --expected="${libomp_expected_library_deps}" ${LIBOMP_OUTPUT_DIRECTORY}/${LIBOMP_LIB_FILE}
232+
COMMAND ${Python3_EXECUTABLE} ${LIBOMP_TOOLS_DIR}/check-depends.py
233+
--expected="${libomp_expected_library_deps}"
234+
${LIBOMP_OUTPUT_DIRECTORY}/${LIBOMP_LIB_FILE}
242235
COMMAND ${CMAKE_COMMAND} -E touch test-deps/.success
243-
DEPENDS omp ${LIBOMP_TOOLS_DIR}/check-depends.pl
236+
DEPENDS omp ${LIBOMP_TOOLS_DIR}/check-depends.py
244237
)

openmp/runtime/cmake/config-ix.cmake

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -219,30 +219,10 @@ if (IA32 OR INTEL64)
219219
set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
220220
endif()
221221

222-
# Find perl executable
223-
# Perl is used to create omp.h (and other headers) along with kmp_i18n_id.inc and kmp_i18n_default.inc
224-
find_package(Perl REQUIRED)
225-
# The perl scripts take the --os=/--arch= flags which expect a certain format for operating systems and arch's.
226-
# Until the perl scripts are removed, the most portable way to handle this is to have all operating systems that
227-
# are neither Windows nor Mac (Most Unix flavors) be considered lin to the perl scripts. This is rooted
228-
# in that all the Perl scripts check the operating system and will fail if it isn't "valid". This
229-
# temporary solution lets us avoid trying to enumerate all the possible OS values inside the Perl modules.
230-
if(WIN32)
231-
set(LIBOMP_PERL_SCRIPT_OS win)
232-
elseif(APPLE)
233-
set(LIBOMP_PERL_SCRIPT_OS mac)
234-
else()
235-
set(LIBOMP_PERL_SCRIPT_OS lin)
236-
endif()
237-
if(IA32)
238-
set(LIBOMP_PERL_SCRIPT_ARCH 32)
239-
elseif(MIC)
240-
set(LIBOMP_PERL_SCRIPT_ARCH mic)
241-
elseif(INTEL64)
242-
set(LIBOMP_PERL_SCRIPT_ARCH 32e)
243-
else()
244-
set(LIBOMP_PERL_SCRIPT_ARCH ${LIBOMP_ARCH})
245-
endif()
222+
# Find python3 executable
223+
# Python3 is used to create kmp_i18n_id.inc and
224+
# kmp_i18n_default.inc and for Windows the *.def files.
225+
find_package(Python3 REQUIRED COMPONENTS Interpreter)
246226

247227
# Checking features
248228
# Check if version symbol assembler directives are supported

openmp/runtime/src/CMakeLists.txt

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ endif()
2828
# Generate message catalog files: kmp_i18n_id.inc and kmp_i18n_default.inc
2929
add_custom_command(
3030
OUTPUT kmp_i18n_id.inc
31-
COMMAND ${PERL_EXECUTABLE} ${LIBOMP_TOOLS_DIR}/message-converter.pl --os=${LIBOMP_PERL_SCRIPT_OS}
32-
--prefix=kmp_i18n --enum=kmp_i18n_id.inc ${LIBOMP_SRC_DIR}/i18n/en_US.txt
33-
DEPENDS ${LIBOMP_SRC_DIR}/i18n/en_US.txt ${LIBOMP_TOOLS_DIR}/message-converter.pl
31+
COMMAND ${Python3_EXECUTABLE} ${LIBOMP_TOOLS_DIR}/message-converter.py
32+
--enum=kmp_i18n_id.inc ${LIBOMP_SRC_DIR}/i18n/en_US.txt
33+
DEPENDS ${LIBOMP_SRC_DIR}/i18n/en_US.txt ${LIBOMP_TOOLS_DIR}/message-converter.py
3434
)
3535
add_custom_command(
3636
OUTPUT kmp_i18n_default.inc
37-
COMMAND ${PERL_EXECUTABLE} ${LIBOMP_TOOLS_DIR}/message-converter.pl --os=${LIBOMP_PERL_SCRIPT_OS}
38-
--prefix=kmp_i18n --default=kmp_i18n_default.inc ${LIBOMP_SRC_DIR}/i18n/en_US.txt
39-
DEPENDS ${LIBOMP_SRC_DIR}/i18n/en_US.txt ${LIBOMP_TOOLS_DIR}/message-converter.pl
37+
COMMAND ${Python3_EXECUTABLE} ${LIBOMP_TOOLS_DIR}/message-converter.py
38+
--default=kmp_i18n_default.inc ${LIBOMP_SRC_DIR}/i18n/en_US.txt
39+
DEPENDS ${LIBOMP_SRC_DIR}/i18n/en_US.txt ${LIBOMP_TOOLS_DIR}/message-converter.py
4040
)
4141

4242
# Set the -D definitions for all sources
@@ -301,11 +301,12 @@ if(WIN32)
301301
# Create the main def file with ordinals to use for building the runtime dll to maintain backwards compatible exports order
302302
libomp_get_gdflags(LIBOMP_GDFLAGS)
303303
libomp_string_to_list("${LIBOMP_GDFLAGS}" LIBOMP_GDFLAGS)
304+
304305
add_custom_command(
305306
OUTPUT ${LIBOMP_GENERATED_DEF_FILE}
306-
COMMAND ${PERL_EXECUTABLE} ${LIBOMP_TOOLS_DIR}/generate-def.pl ${LIBOMP_GDFLAGS} -D NAME=${LIBOMP_LIB_FILE}
307+
COMMAND ${Python3_EXECUTABLE} ${LIBOMP_TOOLS_DIR}/generate-def.py ${LIBOMP_GDFLAGS} --name ${LIBOMP_LIB_FILE}
307308
-o ${LIBOMP_GENERATED_DEF_FILE} ${CMAKE_CURRENT_SOURCE_DIR}/dllexports
308-
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/dllexports ${LIBOMP_TOOLS_DIR}/generate-def.pl
309+
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/dllexports ${LIBOMP_TOOLS_DIR}/generate-def.py
309310
)
310311

311312
if(MSVC)
@@ -317,9 +318,10 @@ if(WIN32)
317318
set_target_properties(libompimp-needed-def-file PROPERTIES FOLDER "OpenMP/Resources")
318319
add_custom_command(
319320
OUTPUT ${LIBOMPIMP_GENERATED_DEF_FILE}
320-
COMMAND ${PERL_EXECUTABLE} ${LIBOMP_TOOLS_DIR}/generate-def.pl ${LIBOMP_GDFLAGS} -D NAME=${LIBOMP_LIB_FILE} -D NOORDINALS
321-
-o ${LIBOMPIMP_GENERATED_DEF_FILE} ${CMAKE_CURRENT_SOURCE_DIR}/dllexports
322-
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/dllexports ${LIBOMP_TOOLS_DIR}/generate-def.pl
321+
COMMAND ${Python3_EXECUTABLE} ${LIBOMP_TOOLS_DIR}/generate-def.py ${LIBOMP_GDFLAGS}
322+
--name ${LIBOMP_LIB_FILE} --no-ordinals
323+
-o ${LIBOMPIMP_GENERATED_DEF_FILE} ${CMAKE_CURRENT_SOURCE_DIR}/dllexports
324+
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/dllexports ${LIBOMP_TOOLS_DIR}/generate-def.py
323325
)
324326
# while this merely generates an import library off a def file, CMAKE still requires it to have a "source" so feed it a dummy one,
325327
# making it a .txt which CMAKE will filter out from the librarian (a .cpp will make lib.exe punt trying to resolve the .def symbols)
@@ -396,9 +398,6 @@ endif()
396398
if(NOT WIN32 AND NOT APPLE)
397399
add_dependencies(libomp-micro-tests libomp-test-execstack)
398400
endif()
399-
if(${MIC})
400-
add_dependencies(libomp-micro-tests libomp-test-instr)
401-
endif()
402401
add_dependencies(libomp-micro-tests libomp-test-deps)
403402

404403
# `omp` needs to be exported if in-tree build.

0 commit comments

Comments
 (0)