Skip to content

Commit 8a14135

Browse files
authored
Reland: [Offload] Don't check in generated files (llvm#141982) (llvm#2572)
2 parents 67e8baa + 4007289 commit 8a14135

File tree

15 files changed

+63
-2765
lines changed

15 files changed

+63
-2765
lines changed

offload/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,8 @@ if(OFFLOAD_ENABLE_EMISSARY_APIS)
447447
DESTINATION ${LIBOMP_HEADERS_INSTALL_PATH})
448448
endif()
449449

450+
add_subdirectory(tools/offload-tblgen)
451+
450452
# Build offloading plugins and device RTLs if they are available.
451453
add_subdirectory(plugins-nextgen)
452454

@@ -457,7 +459,6 @@ add_subdirectory(DeviceRTL)
457459
add_subdirectory(libomptarget)
458460

459461
# FIXME: Re-enable once OMPT design allows
460-
# add_subdirectory(tools/offload-tblgen)
461462
# add_subdirectory(liboffload)
462463

463464
# Add tests.

offload/include/Shared/OffloadErrcodes.inc

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

offload/liboffload/API/CMakeLists.txt

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,40 @@
1-
# The OffloadGenerate target is used to regenerate the generated files in the
2-
# include directory. These files are checked in with the rest of the source,
3-
# therefore it is only needed when making changes to the API.
1+
# We want to clang-format the generated files if possible, since OffloadAPI.h is
2+
# the main public header for liboffload. Generate them in a temporary location,
3+
# then clang-format and copy them to the proper location. If clang-format is
4+
# missing just copy them.
5+
# Ideally we'd just clang-format them in place and avoid the copy but cmake
6+
# gets confused about the same path being a byproduct of two custom commands.
47

5-
find_program(CLANG_FORMAT clang-format PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH)
6-
if (CLANG_FORMAT)
7-
set(LLVM_TARGET_DEFINITIONS ${CMAKE_CURRENT_SOURCE_DIR}/OffloadAPI.td)
8+
set(LLVM_TARGET_DEFINITIONS ${CMAKE_CURRENT_SOURCE_DIR}/OffloadAPI.td)
9+
set(files_to_copy "")
10+
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/generated)
811

9-
tablegen(OFFLOAD OffloadAPI.h -gen-api)
10-
tablegen(OFFLOAD OffloadEntryPoints.inc -gen-entry-points)
11-
tablegen(OFFLOAD OffloadFuncs.inc -gen-func-names)
12-
tablegen(OFFLOAD OffloadImplFuncDecls.inc -gen-impl-func-decls)
13-
tablegen(OFFLOAD OffloadPrint.hpp -gen-print-header)
14-
tablegen(OFFLOAD OffloadErrcodes.inc -gen-errcodes)
12+
macro(offload_tablegen file)
13+
tablegen(OFFLOAD generated/${file}.gen ${ARGN})
14+
list(APPEND files_to_copy ${file})
15+
endmacro()
1516

16-
set(FILES_TO_COPY "OffloadAPI.h;OffloadEntryPoints.inc;OffloadFuncs.inc;OffloadImplFuncDecls.inc;OffloadPrint.hpp")
17-
set(GEN_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../include/generated)
18-
add_public_tablegen_target(OffloadGenerate)
19-
add_custom_command(TARGET OffloadGenerate POST_BUILD COMMAND ${CLANG_FORMAT}
20-
-i ${TABLEGEN_OUTPUT})
21-
add_custom_command(TARGET OffloadGenerate POST_BUILD COMMAND ${CMAKE_COMMAND}
22-
-E copy_if_different ${FILES_TO_COPY} ${GEN_DIR})
23-
add_custom_command(TARGET OffloadGenerate POST_BUILD COMMAND ${CMAKE_COMMAND}
24-
-E copy_if_different OffloadErrcodes.inc "${LIBOMPTARGET_INCLUDE_DIR}/Shared/OffloadErrcodes.inc")
17+
offload_tablegen(OffloadAPI.h -gen-api)
18+
offload_tablegen(OffloadEntryPoints.inc -gen-entry-points)
19+
offload_tablegen(OffloadFuncs.inc -gen-func-names)
20+
offload_tablegen(OffloadImplFuncDecls.inc -gen-impl-func-decls)
21+
offload_tablegen(OffloadPrint.hpp -gen-print-header)
22+
23+
add_public_tablegen_target(OffloadGenerate)
24+
25+
add_custom_target(OffloadAPI DEPENDS OffloadGenerate)
26+
find_program(clang_format clang-format PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH)
27+
if (clang_format)
28+
foreach(file IN LISTS files_to_copy)
29+
add_custom_command(
30+
OUTPUT ${file}
31+
COMMAND ${clang_format} -i generated/${file}.gen
32+
COMMAND ${CMAKE_COMMAND} -E copy_if_different generated/${file}.gen ${CMAKE_CURRENT_BINARY_DIR}/${file}
33+
DEPENDS generated/${file}.gen
34+
)
35+
add_custom_target(OffloadAPI.${file} DEPENDS ${file})
36+
add_dependencies(OffloadAPI OffloadAPI.${file})
37+
endforeach()
2538
else()
2639
message(WARNING "clang-format not found, the generated Offload API headers will not be formatted")
2740
foreach(file IN LISTS files_to_copy)

offload/liboffload/CMakeLists.txt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ add_llvm_library(
88
LINK_COMPONENTS
99
FrontendOpenMP
1010
Support
11+
12+
DEPENDS
13+
OffloadAPI
14+
PluginErrcodes
1115
)
1216

1317
foreach(plugin IN LISTS LIBOMPTARGET_PLUGINS_TO_BUILD)
@@ -19,11 +23,13 @@ if(LIBOMP_HAVE_VERSION_SCRIPT_FLAG)
1923
endif()
2024

2125
target_include_directories(LLVMOffload PUBLIC
26+
${CMAKE_CURRENT_BINARY_DIR}/API
2227
${CMAKE_CURRENT_BINARY_DIR}/../include
2328
${CMAKE_CURRENT_SOURCE_DIR}/include
24-
${CMAKE_CURRENT_SOURCE_DIR}/include/generated
2529
${CMAKE_CURRENT_SOURCE_DIR}/../include
26-
${CMAKE_CURRENT_SOURCE_DIR}/../plugins-nextgen/common/include)
30+
${CMAKE_CURRENT_SOURCE_DIR}/../plugins-nextgen/common/include
31+
${CMAKE_CURRENT_BINARY_DIR}/../plugins-nextgen/common/include
32+
)
2733

2834
target_compile_options(LLVMOffload PRIVATE ${offload_compile_flags})
2935
target_link_options(LLVMOffload PRIVATE ${offload_link_flags})
@@ -39,5 +45,5 @@ set_target_properties(LLVMOffload PROPERTIES
3945
BUILD_RPATH "$ORIGIN:${CMAKE_CURRENT_BINARY_DIR}/..")
4046
install(TARGETS LLVMOffload LIBRARY COMPONENT LLVMOffload DESTINATION "${OFFLOAD_INSTALL_LIBDIR}")
4147

42-
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/generated/OffloadAPI.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include/offload)
43-
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/generated/OffloadPrint.hpp DESTINATION ${CMAKE_INSTALL_PREFIX}/include/offload)
48+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/API/OffloadAPI.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include/offload)
49+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/API/OffloadPrint.hpp DESTINATION ${CMAKE_INSTALL_PREFIX}/include/offload)

0 commit comments

Comments
 (0)