Skip to content

Commit e0ae779

Browse files
[libc] delete hdrgen (llvm#117220)
Thanks to the effort of @RoseZhang03 and @aaryanshukla under the guidance of @michaelrj-google and @amykhuang, we now have newhdrgen and no longer have a dependency on TableGen and thus LLVM in order to start bootstrapping a full build. This PR removes: - LIBC_HDRGEN_EXE; the in tree newhdrgen is the only hdrgen that can be used. - LIBC_USE_NEW_HEADER_GEN; newhdrgen is the default and only option. - LIBC_HDRGEN_ONLY; there is no need to have a distinct build step for old hdrgen. - libc-api-test and libc-api-test-tidy build targets. - Deletes all .td files. It does not rename newhdrgen to just hdrgen. Will follow up with a distinct PR for that. Link: llvm#117209 Link: llvm#117254 Fixes: llvm#117208
1 parent fdd09e9 commit e0ae779

38 files changed

+50
-6942
lines changed

libc/CMakeLists.txt

Lines changed: 16 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -50,52 +50,27 @@ set(LIBC_NAMESPACE ${default_namespace}
5050
CACHE STRING "The namespace to use to enclose internal implementations. Must start with '__llvm_libc'."
5151
)
5252

53-
54-
add_subdirectory(newhdrgen)
55-
56-
57-
if(LLVM_LIBC_FULL_BUILD OR LLVM_LIBC_GPU_BUILD)
58-
if(NOT LIBC_HDRGEN_EXE)
59-
# We need to set up hdrgen first since other targets depend on it.
60-
add_subdirectory(utils/LibcTableGenUtil)
61-
add_subdirectory(utils/HdrGen)
62-
# Calling add_tablegen sets variables like LIBC_TABLEGEN_EXE in
63-
# PARENT_SCOPE which get lost until saved in the cache.
64-
set(LIBC_TABLEGEN_EXE "${LIBC_TABLEGEN_EXE}" CACHE INTERNAL "")
65-
set(LIBC_TABLEGEN_TARGET "${LIBC_TABLEGEN_TARGET}" CACHE INTERNAL "")
66-
else()
67-
message(STATUS "Will use ${LIBC_HDRGEN_EXE} for libc header generation.")
68-
endif()
69-
endif()
7053
# We will build the GPU utilities if we are not doing a runtimes build.
7154
option(LIBC_BUILD_GPU_LOADER "Always build the GPU loader utilities" OFF)
72-
if(LIBC_BUILD_GPU_LOADER OR (LLVM_LIBC_GPU_BUILD AND NOT LLVM_RUNTIMES_BUILD))
73-
add_subdirectory(utils/gpu)
74-
endif()
75-
76-
option(LIBC_USE_NEW_HEADER_GEN "Generate header files using new headergen instead of the old one" ON)
77-
78-
set(NEED_LIBC_HDRGEN FALSE)
79-
if(NOT LLVM_RUNTIMES_BUILD)
80-
if("libc" IN_LIST LLVM_ENABLE_RUNTIMES)
81-
set(NEED_LIBC_HDRGEN TRUE)
82-
else()
83-
foreach(_name ${LLVM_RUNTIME_TARGETS})
84-
if("libc" IN_LIST RUNTIMES_${_name}_LLVM_ENABLE_RUNTIMES)
85-
set(NEED_LIBC_HDRGEN TRUE)
86-
break()
55+
if(LIBC_BUILD_GPU_LOADER OR NOT LLVM_RUNTIMES_BUILD)
56+
foreach(_name ${LLVM_RUNTIME_TARGETS})
57+
if("libc" IN_LIST RUNTIMES_${_name}_LLVM_ENABLE_RUNTIMES)
58+
if("${_name}" STREQUAL "amdgcn-amd-amdhsa" OR "${_name}" STREQUAL "nvptx64-nvidia-cuda")
59+
set(LIBC_NEED_LOADER_UTILS TRUE)
8760
endif()
88-
endforeach()
61+
endif()
62+
endforeach()
63+
if("${LIBC_TARGET_TRIPLE}" STREQUAL "amdgcn-amd-amdhsa" OR
64+
"${LIBC_TARGET_TRIPLE}" STREQUAL "nvptx64-nvidia-cuda")
65+
set(LIBC_NEED_LOADER_UTILS TRUE)
66+
endif()
67+
if(LIBC_NEED_LOADER_UTILS)
68+
add_subdirectory(utils/gpu)
69+
return()
8970
endif()
9071
endif()
91-
option(LIBC_HDRGEN_ONLY "Only build the 'libc-hdrgen' executable" OFF)
92-
if(LIBC_HDRGEN_ONLY OR NEED_LIBC_HDRGEN)
93-
# When libc is build as part of the runtimes/bootstrap build's CMake run, we
94-
# only need to build the host tools to build the libc. So, we just do enough
95-
# to build libc-hdrgen and return.
96-
return()
97-
endif()
98-
unset(NEED_LIBC_HDRGEN)
72+
73+
add_subdirectory(newhdrgen)
9974

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

libc/cmake/modules/LLVMLibCHeaderRules.cmake

Lines changed: 16 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ function(add_header target_name)
7171
)
7272
endfunction(add_header)
7373

74-
function(add_gen_header2 target_name)
74+
function(add_gen_header target_name)
7575
cmake_parse_arguments(
76-
"ADD_GEN_HDR2"
76+
"ADD_GEN_HDR"
7777
"PUBLIC" # No optional arguments
7878
"YAML_FILE;DEF_FILE;GEN_HDR" # Single value arguments
7979
"DEPENDS" # Multi value arguments
@@ -84,25 +84,25 @@ function(add_gen_header2 target_name)
8484
add_library(${fq_target_name} INTERFACE)
8585
return()
8686
endif()
87-
if(NOT ADD_GEN_HDR2_DEF_FILE)
88-
message(FATAL_ERROR "`add_gen_hdr2` rule requires DEF_FILE to be specified.")
87+
if(NOT ADD_GEN_HDR_DEF_FILE)
88+
message(FATAL_ERROR "`add_gen_hdr` rule requires DEF_FILE to be specified.")
8989
endif()
90-
if(NOT ADD_GEN_HDR2_GEN_HDR)
91-
message(FATAL_ERROR "`add_gen_hdr2` rule requires GEN_HDR to be specified.")
90+
if(NOT ADD_GEN_HDR_GEN_HDR)
91+
message(FATAL_ERROR "`add_gen_hdr` rule requires GEN_HDR to be specified.")
9292
endif()
93-
if(NOT ADD_GEN_HDR2_YAML_FILE)
94-
message(FATAL_ERROR "`add_gen_hdr2` rule requires YAML_FILE to be specified.")
93+
if(NOT ADD_GEN_HDR_YAML_FILE)
94+
message(FATAL_ERROR "`add_gen_hdr` rule requires YAML_FILE to be specified.")
9595
endif()
9696

97-
set(absolute_path ${CMAKE_CURRENT_SOURCE_DIR}/${ADD_GEN_HDR2_GEN_HDR})
97+
set(absolute_path ${CMAKE_CURRENT_SOURCE_DIR}/${ADD_GEN_HDR_GEN_HDR})
9898
file(RELATIVE_PATH relative_path ${LIBC_INCLUDE_SOURCE_DIR} ${absolute_path})
9999
set(out_file ${LIBC_INCLUDE_DIR}/${relative_path})
100-
set(yaml_file ${CMAKE_SOURCE_DIR}/${ADD_GEN_HDR2_YAML_FILE})
101-
set(def_file ${CMAKE_CURRENT_SOURCE_DIR}/${ADD_GEN_HDR2_DEF_FILE})
100+
set(yaml_file ${CMAKE_SOURCE_DIR}/${ADD_GEN_HDR_YAML_FILE})
101+
set(def_file ${CMAKE_CURRENT_SOURCE_DIR}/${ADD_GEN_HDR_DEF_FILE})
102102

103103
set(fq_data_files "")
104-
if(ADD_GEN_HDR2_DATA_FILES)
105-
foreach(data_file IN LISTS ADD_GEN_HDR2_DATA_FILES)
104+
if(ADD_GEN_HDR_DATA_FILES)
105+
foreach(data_file IN LISTS ADD_GEN_HDR_DATA_FILES)
106106
list(APPEND fq_data_files "${CMAKE_CURRENT_SOURCE_DIR}/${data_file}")
107107
endforeach(data_file)
108108
endif()
@@ -118,7 +118,7 @@ function(add_gen_header2 target_name)
118118
${entry_points}
119119
--output_dir ${out_file}
120120
DEPENDS ${yaml_file} ${def_file} ${fq_data_files}
121-
COMMENT "Generating header ${ADD_GEN_HDR2_GEN_HDR} from ${yaml_file} and ${def_file}"
121+
COMMENT "Generating header ${ADD_GEN_HDR_GEN_HDR} from ${yaml_file} and ${def_file}"
122122
)
123123
if(LIBC_TARGET_OS_IS_GPU)
124124
file(MAKE_DIRECTORY ${LIBC_INCLUDE_DIR}/llvm-libc-decls)
@@ -136,132 +136,6 @@ function(add_gen_header2 target_name)
136136
)
137137
endif()
138138

139-
if(ADD_GEN_HDR2_DEPENDS)
140-
get_fq_deps_list(fq_deps_list ${ADD_GEN_HDR2_DEPENDS})
141-
# Dependencies of a add_header target can only be another add_gen_header target
142-
# or an add_header target.
143-
foreach(dep IN LISTS fq_deps_list)
144-
get_target_property(header_file ${dep} HEADER_FILE_PATH)
145-
if(NOT header_file)
146-
message(FATAL_ERROR "Invalid dependency '${dep}' for '${fq_target_name}'.")
147-
endif()
148-
endforeach()
149-
endif()
150-
set(generated_hdr_target ${fq_target_name}.__generated_hdr__)
151-
add_custom_target(
152-
${generated_hdr_target}
153-
DEPENDS ${out_file} ${fq_deps_list} ${decl_out_file}
154-
)
155-
156-
add_header_library(
157-
${target_name}
158-
HDRS
159-
${out_file}
160-
)
161-
162-
add_dependencies(${fq_target_name} ${generated_hdr_target})
163-
164-
set_target_properties(
165-
${fq_target_name}
166-
PROPERTIES
167-
HEADER_FILE_PATH ${out_file}
168-
DECLS_FILE_PATH "${decl_out_file}"
169-
DEPS "${fq_deps_list}"
170-
)
171-
172-
173-
endfunction(add_gen_header2)
174-
175-
# Usage:
176-
# add_gen_header(
177-
# <target name>
178-
# DEF_FILE <.h.def file>
179-
# GEN_HDR <generated header file name>
180-
# PARAMS <list of name=value pairs>
181-
# DATA_FILES <list input data files>
182-
# )
183-
function(add_gen_header target_name)
184-
cmake_parse_arguments(
185-
"ADD_GEN_HDR"
186-
"PUBLIC" # No optional arguments
187-
"DEF_FILE;GEN_HDR" # Single value arguments
188-
"PARAMS;DATA_FILES;DEPENDS" # Multi value arguments
189-
${ARGN}
190-
)
191-
get_fq_target_name(${target_name} fq_target_name)
192-
if(NOT LLVM_LIBC_FULL_BUILD)
193-
# We don't want to use generated headers if we are doing a non-full-build.
194-
add_library(${fq_target_name} INTERFACE)
195-
return()
196-
endif()
197-
if(NOT ADD_GEN_HDR_DEF_FILE)
198-
message(FATAL_ERROR "`add_gen_hdr` rule requires DEF_FILE to be specified.")
199-
endif()
200-
if(NOT ADD_GEN_HDR_GEN_HDR)
201-
message(FATAL_ERROR "`add_gen_hdr` rule requires GEN_HDR to be specified.")
202-
endif()
203-
204-
set(absolute_path ${CMAKE_CURRENT_SOURCE_DIR}/${ADD_GEN_HDR_GEN_HDR})
205-
file(RELATIVE_PATH relative_path ${LIBC_INCLUDE_SOURCE_DIR} ${absolute_path})
206-
set(out_file ${LIBC_INCLUDE_DIR}/${relative_path})
207-
set(in_file ${CMAKE_CURRENT_SOURCE_DIR}/${ADD_GEN_HDR_DEF_FILE})
208-
209-
set(fq_data_files "")
210-
if(ADD_GEN_HDR_DATA_FILES)
211-
foreach(data_file IN LISTS ADD_GEN_HDR_DATA_FILES)
212-
list(APPEND fq_data_files "${CMAKE_CURRENT_SOURCE_DIR}/${data_file}")
213-
endforeach(data_file)
214-
endif()
215-
216-
set(replacement_params "")
217-
if(ADD_GEN_HDR_PARAMS)
218-
list(APPEND replacement_params "--args" ${ADD_GEN_HDR_PARAMS})
219-
endif()
220-
221-
set(gen_hdr_script "${LIBC_BUILD_SCRIPTS_DIR}/gen_hdr.py")
222-
223-
file(GLOB td_includes ${LIBC_SOURCE_DIR}/spec/*.td)
224-
225-
set(ENTRYPOINT_NAME_LIST_ARG ${TARGET_ENTRYPOINT_NAME_LIST})
226-
list(TRANSFORM ENTRYPOINT_NAME_LIST_ARG PREPEND "--e=")
227-
228-
if(LIBC_HDRGEN_EXE)
229-
set(hdrgen_exe ${LIBC_HDRGEN_EXE})
230-
else()
231-
set(hdrgen_exe ${LIBC_TABLEGEN_EXE})
232-
set(hdrgen_deps "${LIBC_TABLEGEN_EXE};${LIBC_TABLEGEN_TARGET}")
233-
endif()
234-
add_custom_command(
235-
OUTPUT ${out_file}
236-
COMMAND ${hdrgen_exe} -o ${out_file} --header ${ADD_GEN_HDR_GEN_HDR}
237-
--def ${in_file} ${replacement_params} -I ${LIBC_SOURCE_DIR}
238-
${ENTRYPOINT_NAME_LIST_ARG}
239-
${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/api.td
240-
241-
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
242-
DEPENDS ${in_file} ${fq_data_files} ${td_includes}
243-
${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/api.td
244-
${hdrgen_deps}
245-
)
246-
247-
if(LIBC_TARGET_OS_IS_GPU)
248-
file(MAKE_DIRECTORY ${LIBC_INCLUDE_DIR}/llvm-libc-decls)
249-
file(MAKE_DIRECTORY ${LIBC_INCLUDE_DIR}/llvm-libc-decls/gpu)
250-
set(decl_out_file ${LIBC_INCLUDE_DIR}/llvm-libc-decls/${relative_path})
251-
add_custom_command(
252-
OUTPUT ${decl_out_file}
253-
COMMAND ${hdrgen_exe} -o ${decl_out_file}
254-
--header ${ADD_GEN_HDR_GEN_HDR} --def ${in_file} --export-decls
255-
${replacement_params} -I ${LIBC_SOURCE_DIR} ${ENTRYPOINT_NAME_LIST_ARG}
256-
${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/api.td
257-
258-
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
259-
DEPENDS ${in_file} ${fq_data_files} ${td_includes}
260-
${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/api.td
261-
${hdrgen_deps}
262-
)
263-
endif()
264-
265139
if(ADD_GEN_HDR_DEPENDS)
266140
get_fq_deps_list(fq_deps_list ${ADD_GEN_HDR_DEPENDS})
267141
# Dependencies of a add_header target can only be another add_gen_header target
@@ -285,9 +159,6 @@ function(add_gen_header target_name)
285159
${out_file}
286160
)
287161

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

293164
set_target_properties(
@@ -297,4 +168,6 @@ function(add_gen_header target_name)
297168
DECLS_FILE_PATH "${decl_out_file}"
298169
DEPS "${fq_deps_list}"
299170
)
171+
172+
300173
endfunction(add_gen_header)

libc/config/baremetal/api.td

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

libc/config/gpu/api.td

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

0 commit comments

Comments
 (0)