Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion offload/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,8 @@ set(LIBOMPTARGET_LLVM_LIBRARY_DIR "${LLVM_LIBRARY_DIR}" CACHE STRING
set(LIBOMPTARGET_LLVM_LIBRARY_INTDIR "${LIBOMPTARGET_INTDIR}" CACHE STRING
"Path to folder where intermediate libraries will be output")

add_subdirectory(tools/offload-tblgen)

# Build offloading plugins and device RTLs if they are available.
add_subdirectory(plugins-nextgen)
add_subdirectory(DeviceRTL)
Expand All @@ -371,7 +373,6 @@ add_subdirectory(tools)
# Build target agnostic offloading library.
add_subdirectory(libomptarget)

add_subdirectory(tools/offload-tblgen)
add_subdirectory(liboffload)

# Add tests.
Expand Down
51 changes: 0 additions & 51 deletions offload/include/Shared/OffloadErrcodes.inc

This file was deleted.

65 changes: 41 additions & 24 deletions offload/liboffload/API/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,29 +1,46 @@
# The OffloadGenerate target is used to regenerate the generated files in the
# include directory. These files are checked in with the rest of the source,
# therefore it is only needed when making changes to the API.
# We want to clang-format the generated files if possible, since OffloadAPI.h is
# the main public header for liboffload. Generate them in a temporary location,
# then clang-format and copy them to the proper location. If clang-format is
# missing just copy them.
# Ideally we'd just clang-format them in place and avoid the copy but cmake
# gets confused about the same path being a byproduct of two custom commands.

find_program(CLANG_FORMAT clang-format PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH)
if (CLANG_FORMAT)
set(LLVM_TARGET_DEFINITIONS ${CMAKE_CURRENT_SOURCE_DIR}/OffloadAPI.td)
set(LLVM_TARGET_DEFINITIONS ${CMAKE_CURRENT_SOURCE_DIR}/OffloadAPI.td)
set(files_to_copy "")

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

set(FILES_TO_COPY "OffloadAPI.h;OffloadEntryPoints.inc;OffloadFuncs.inc;OffloadImplFuncDecls.inc;OffloadPrint.hpp")
set(GEN_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../include/generated)
add_public_tablegen_target(OffloadGenerate)
add_custom_command(TARGET OffloadGenerate POST_BUILD COMMAND ${CLANG_FORMAT}
-i ${TABLEGEN_OUTPUT})
add_custom_command(TARGET OffloadGenerate POST_BUILD COMMAND ${CMAKE_COMMAND}
-E copy_if_different ${FILES_TO_COPY} ${GEN_DIR})
add_custom_command(TARGET OffloadGenerate POST_BUILD COMMAND ${CMAKE_COMMAND}
-E copy_if_different OffloadErrcodes.inc "${LIBOMPTARGET_INCLUDE_DIR}/Shared/OffloadErrcodes.inc")
offload_tablegen(OffloadAPI.h -gen-api)
offload_tablegen(OffloadEntryPoints.inc -gen-entry-points)
offload_tablegen(OffloadFuncs.inc -gen-func-names)
offload_tablegen(OffloadImplFuncDecls.inc -gen-impl-func-decls)
offload_tablegen(OffloadPrint.hpp -gen-print-header)

add_public_tablegen_target(OffloadGenerate)

add_custom_target(OffloadAPI DEPENDS OffloadGenerate)
find_program(clang_format clang-format PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH)
if (clang_format)
foreach(file IN LISTS files_to_copy)
add_custom_command(
OUTPUT ${file}
COMMAND ${clang_format} -i generated/${file}.gen
COMMAND ${CMAKE_COMMAND} -E copy_if_different generated/${file}.gen ${CMAKE_CURRENT_BINARY_DIR}/${file}
DEPENDS generated/${file}.gen
)
add_custom_target(OffloadAPI.${file} DEPENDS ${file})
add_dependencies(OffloadAPI OffloadAPI.${file})
endforeach()
else()
message(WARNING "clang-format was not found, so the OffloadGenerate target\
will not be available. Offload will still build, but you will not be\
able to make changes to the API.")
message(WARNING "clang-format not found, the generated Offload API headers will not be formatted")
foreach(file IN LISTS files_to_copy)
add_custom_command(
OUTPUT ${file}
COMMAND ${CMAKE_COMMAND} -E copy_if_different generated/${file}.gen ${CMAKE_CURRENT_BINARY_DIR}/${file}
DEPENDS generated/${file}.gen
)
endforeach()
endif()
14 changes: 10 additions & 4 deletions offload/liboffload/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ add_llvm_library(
LINK_COMPONENTS
FrontendOpenMP
Support

DEPENDS
OffloadAPI
PluginErrcodes
)

foreach(plugin IN LISTS LIBOMPTARGET_PLUGINS_TO_BUILD)
Expand All @@ -19,11 +23,13 @@ if(LLVM_HAVE_LINK_VERSION_SCRIPT)
endif()

target_include_directories(LLVMOffload PUBLIC
${CMAKE_CURRENT_BINARY_DIR}/API
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it still find the error codes? Those were in shared/ because it needs to be used by the plugins as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it seems to work fine, the ${CMAKE_CURRENT_BINARY_DIR}/../include line below means it finds Shared/OffloadErrcodes.inc

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although I do wonder if it should be getting the dependency on the shared header from the plugins themselves rather than libomptarget

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a missing dependency between liboffload and the LibomptargetOffloadErrcodes target, I've fixed that now

${CMAKE_CURRENT_BINARY_DIR}/../include
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/include/generated
${CMAKE_CURRENT_SOURCE_DIR}/../include
${CMAKE_CURRENT_SOURCE_DIR}/../plugins-nextgen/common/include)
${CMAKE_CURRENT_SOURCE_DIR}/../plugins-nextgen/common/include
${CMAKE_CURRENT_BINARY_DIR}/../plugins-nextgen/common/include
)

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

install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/generated/OffloadAPI.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include/offload)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/generated/OffloadPrint.hpp DESTINATION ${CMAKE_INSTALL_PREFIX}/include/offload)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/API/OffloadAPI.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include/offload)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/API/OffloadPrint.hpp DESTINATION ${CMAKE_INSTALL_PREFIX}/include/offload)
Loading
Loading