Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[libc] delete hdrgen #117220

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
37 changes: 0 additions & 37 deletions libc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,49 +54,12 @@ set(LIBC_NAMESPACE ${default_namespace}
add_subdirectory(newhdrgen)


if(LLVM_LIBC_FULL_BUILD OR LLVM_LIBC_GPU_BUILD)
if(NOT LIBC_HDRGEN_EXE)
# We need to set up hdrgen first since other targets depend on it.
add_subdirectory(utils/LibcTableGenUtil)
add_subdirectory(utils/HdrGen)
# Calling add_tablegen sets variables like LIBC_TABLEGEN_EXE in
# PARENT_SCOPE which get lost until saved in the cache.
set(LIBC_TABLEGEN_EXE "${LIBC_TABLEGEN_EXE}" CACHE INTERNAL "")
set(LIBC_TABLEGEN_TARGET "${LIBC_TABLEGEN_TARGET}" CACHE INTERNAL "")
else()
message(STATUS "Will use ${LIBC_HDRGEN_EXE} for libc header generation.")
endif()
endif()
# We will build the GPU utilities if we are not doing a runtimes build.
option(LIBC_BUILD_GPU_LOADER "Always build the GPU loader utilities" OFF)
if(LIBC_BUILD_GPU_LOADER OR (LLVM_LIBC_GPU_BUILD AND NOT LLVM_RUNTIMES_BUILD))
add_subdirectory(utils/gpu)
endif()

option(LIBC_USE_NEW_HEADER_GEN "Generate header files using new headergen instead of the old one" ON)

set(NEED_LIBC_HDRGEN FALSE)
if(NOT LLVM_RUNTIMES_BUILD)
if("libc" IN_LIST LLVM_ENABLE_RUNTIMES)
set(NEED_LIBC_HDRGEN TRUE)
else()
foreach(_name ${LLVM_RUNTIME_TARGETS})
if("libc" IN_LIST RUNTIMES_${_name}_LLVM_ENABLE_RUNTIMES)
set(NEED_LIBC_HDRGEN TRUE)
break()
endif()
endforeach()
endif()
endif()
option(LIBC_HDRGEN_ONLY "Only build the 'libc-hdrgen' executable" OFF)
if(LIBC_HDRGEN_ONLY OR NEED_LIBC_HDRGEN)
# When libc is build as part of the runtimes/bootstrap build's CMake run, we
# only need to build the host tools to build the libc. So, we just do enough
# to build libc-hdrgen and return.
return()
endif()
unset(NEED_LIBC_HDRGEN)

option(LIBC_CMAKE_VERBOSE_LOGGING
"Log details warnings and notifications during CMake configuration." OFF)

Expand Down
159 changes: 16 additions & 143 deletions libc/cmake/modules/LLVMLibCHeaderRules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ function(add_header target_name)
)
endfunction(add_header)

function(add_gen_header2 target_name)
function(add_gen_header target_name)
cmake_parse_arguments(
"ADD_GEN_HDR2"
"ADD_GEN_HDR"
"PUBLIC" # No optional arguments
"YAML_FILE;DEF_FILE;GEN_HDR" # Single value arguments
"DEPENDS" # Multi value arguments
Expand All @@ -84,25 +84,25 @@ function(add_gen_header2 target_name)
add_library(${fq_target_name} INTERFACE)
return()
endif()
if(NOT ADD_GEN_HDR2_DEF_FILE)
message(FATAL_ERROR "`add_gen_hdr2` rule requires DEF_FILE to be specified.")
if(NOT ADD_GEN_HDR_DEF_FILE)
message(FATAL_ERROR "`add_gen_hdr` rule requires DEF_FILE to be specified.")
endif()
if(NOT ADD_GEN_HDR2_GEN_HDR)
message(FATAL_ERROR "`add_gen_hdr2` rule requires GEN_HDR to be specified.")
if(NOT ADD_GEN_HDR_GEN_HDR)
message(FATAL_ERROR "`add_gen_hdr` rule requires GEN_HDR to be specified.")
endif()
if(NOT ADD_GEN_HDR2_YAML_FILE)
message(FATAL_ERROR "`add_gen_hdr2` rule requires YAML_FILE to be specified.")
if(NOT ADD_GEN_HDR_YAML_FILE)
message(FATAL_ERROR "`add_gen_hdr` rule requires YAML_FILE to be specified.")
endif()

set(absolute_path ${CMAKE_CURRENT_SOURCE_DIR}/${ADD_GEN_HDR2_GEN_HDR})
set(absolute_path ${CMAKE_CURRENT_SOURCE_DIR}/${ADD_GEN_HDR_GEN_HDR})
file(RELATIVE_PATH relative_path ${LIBC_INCLUDE_SOURCE_DIR} ${absolute_path})
set(out_file ${LIBC_INCLUDE_DIR}/${relative_path})
set(yaml_file ${CMAKE_SOURCE_DIR}/${ADD_GEN_HDR2_YAML_FILE})
set(def_file ${CMAKE_CURRENT_SOURCE_DIR}/${ADD_GEN_HDR2_DEF_FILE})
set(yaml_file ${CMAKE_SOURCE_DIR}/${ADD_GEN_HDR_YAML_FILE})
set(def_file ${CMAKE_CURRENT_SOURCE_DIR}/${ADD_GEN_HDR_DEF_FILE})

set(fq_data_files "")
if(ADD_GEN_HDR2_DATA_FILES)
foreach(data_file IN LISTS ADD_GEN_HDR2_DATA_FILES)
if(ADD_GEN_HDR_DATA_FILES)
foreach(data_file IN LISTS ADD_GEN_HDR_DATA_FILES)
list(APPEND fq_data_files "${CMAKE_CURRENT_SOURCE_DIR}/${data_file}")
endforeach(data_file)
endif()
Expand All @@ -118,7 +118,7 @@ function(add_gen_header2 target_name)
${entry_points}
--output_dir ${out_file}
DEPENDS ${yaml_file} ${def_file} ${fq_data_files}
COMMENT "Generating header ${ADD_GEN_HDR2_GEN_HDR} from ${yaml_file} and ${def_file}"
COMMENT "Generating header ${ADD_GEN_HDR_GEN_HDR} from ${yaml_file} and ${def_file}"
)
if(LIBC_TARGET_OS_IS_GPU)
file(MAKE_DIRECTORY ${LIBC_INCLUDE_DIR}/llvm-libc-decls)
Expand All @@ -136,132 +136,6 @@ function(add_gen_header2 target_name)
)
endif()

if(ADD_GEN_HDR2_DEPENDS)
get_fq_deps_list(fq_deps_list ${ADD_GEN_HDR2_DEPENDS})
# Dependencies of a add_header target can only be another add_gen_header target
# or an add_header target.
foreach(dep IN LISTS fq_deps_list)
get_target_property(header_file ${dep} HEADER_FILE_PATH)
if(NOT header_file)
message(FATAL_ERROR "Invalid dependency '${dep}' for '${fq_target_name}'.")
endif()
endforeach()
endif()
set(generated_hdr_target ${fq_target_name}.__generated_hdr__)
add_custom_target(
${generated_hdr_target}
DEPENDS ${out_file} ${fq_deps_list} ${decl_out_file}
)

add_header_library(
${target_name}
HDRS
${out_file}
)

add_dependencies(${fq_target_name} ${generated_hdr_target})

set_target_properties(
${fq_target_name}
PROPERTIES
HEADER_FILE_PATH ${out_file}
DECLS_FILE_PATH "${decl_out_file}"
DEPS "${fq_deps_list}"
)


endfunction(add_gen_header2)

# Usage:
# add_gen_header(
# <target name>
# DEF_FILE <.h.def file>
# GEN_HDR <generated header file name>
# PARAMS <list of name=value pairs>
# DATA_FILES <list input data files>
# )
function(add_gen_header target_name)
cmake_parse_arguments(
"ADD_GEN_HDR"
"PUBLIC" # No optional arguments
"DEF_FILE;GEN_HDR" # Single value arguments
"PARAMS;DATA_FILES;DEPENDS" # Multi value arguments
${ARGN}
)
get_fq_target_name(${target_name} fq_target_name)
if(NOT LLVM_LIBC_FULL_BUILD)
# We don't want to use generated headers if we are doing a non-full-build.
add_library(${fq_target_name} INTERFACE)
return()
endif()
if(NOT ADD_GEN_HDR_DEF_FILE)
message(FATAL_ERROR "`add_gen_hdr` rule requires DEF_FILE to be specified.")
endif()
if(NOT ADD_GEN_HDR_GEN_HDR)
message(FATAL_ERROR "`add_gen_hdr` rule requires GEN_HDR to be specified.")
endif()

set(absolute_path ${CMAKE_CURRENT_SOURCE_DIR}/${ADD_GEN_HDR_GEN_HDR})
file(RELATIVE_PATH relative_path ${LIBC_INCLUDE_SOURCE_DIR} ${absolute_path})
set(out_file ${LIBC_INCLUDE_DIR}/${relative_path})
set(in_file ${CMAKE_CURRENT_SOURCE_DIR}/${ADD_GEN_HDR_DEF_FILE})

set(fq_data_files "")
if(ADD_GEN_HDR_DATA_FILES)
foreach(data_file IN LISTS ADD_GEN_HDR_DATA_FILES)
list(APPEND fq_data_files "${CMAKE_CURRENT_SOURCE_DIR}/${data_file}")
endforeach(data_file)
endif()

set(replacement_params "")
if(ADD_GEN_HDR_PARAMS)
list(APPEND replacement_params "--args" ${ADD_GEN_HDR_PARAMS})
endif()

set(gen_hdr_script "${LIBC_BUILD_SCRIPTS_DIR}/gen_hdr.py")

file(GLOB td_includes ${LIBC_SOURCE_DIR}/spec/*.td)

set(ENTRYPOINT_NAME_LIST_ARG ${TARGET_ENTRYPOINT_NAME_LIST})
list(TRANSFORM ENTRYPOINT_NAME_LIST_ARG PREPEND "--e=")

if(LIBC_HDRGEN_EXE)
set(hdrgen_exe ${LIBC_HDRGEN_EXE})
else()
set(hdrgen_exe ${LIBC_TABLEGEN_EXE})
set(hdrgen_deps "${LIBC_TABLEGEN_EXE};${LIBC_TABLEGEN_TARGET}")
endif()
add_custom_command(
OUTPUT ${out_file}
COMMAND ${hdrgen_exe} -o ${out_file} --header ${ADD_GEN_HDR_GEN_HDR}
--def ${in_file} ${replacement_params} -I ${LIBC_SOURCE_DIR}
${ENTRYPOINT_NAME_LIST_ARG}
${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/api.td

WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS ${in_file} ${fq_data_files} ${td_includes}
${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/api.td
${hdrgen_deps}
)

if(LIBC_TARGET_OS_IS_GPU)
file(MAKE_DIRECTORY ${LIBC_INCLUDE_DIR}/llvm-libc-decls)
file(MAKE_DIRECTORY ${LIBC_INCLUDE_DIR}/llvm-libc-decls/gpu)
set(decl_out_file ${LIBC_INCLUDE_DIR}/llvm-libc-decls/${relative_path})
add_custom_command(
OUTPUT ${decl_out_file}
COMMAND ${hdrgen_exe} -o ${decl_out_file}
--header ${ADD_GEN_HDR_GEN_HDR} --def ${in_file} --export-decls
${replacement_params} -I ${LIBC_SOURCE_DIR} ${ENTRYPOINT_NAME_LIST_ARG}
${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/api.td

WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS ${in_file} ${fq_data_files} ${td_includes}
${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/api.td
${hdrgen_deps}
)
endif()

if(ADD_GEN_HDR_DEPENDS)
get_fq_deps_list(fq_deps_list ${ADD_GEN_HDR_DEPENDS})
# Dependencies of a add_header target can only be another add_gen_header target
Expand All @@ -285,9 +159,6 @@ function(add_gen_header target_name)
${out_file}
)

# We add the dependencies separately and not list under add_header_library's
# DEPENDS option above. This is because, deps of add_header_library are
# used with target_link_libraries.
add_dependencies(${fq_target_name} ${generated_hdr_target})

set_target_properties(
Expand All @@ -297,4 +168,6 @@ function(add_gen_header target_name)
DECLS_FILE_PATH "${decl_out_file}"
DEPS "${fq_deps_list}"
)


endfunction(add_gen_header)
59 changes: 0 additions & 59 deletions libc/config/baremetal/api.td

This file was deleted.

50 changes: 0 additions & 50 deletions libc/config/gpu/api.td

This file was deleted.

Loading
Loading