qiongsiwu1 created this revision.
qiongsiwu1 added reviewers: jsji, daltenty, nemanjai.
qiongsiwu1 added a project: clang.
Herald added subscribers: steven.zhang, pengfei, mgorny, dschuff.
Herald added a project: All.
qiongsiwu1 requested review of this revision.
Herald added subscribers: cfe-commits, aheejin.

The goal of this patch is to improve distribution build's flexibility to 
include only applicable header files.

Currently, the `clang-resource-headers` target contains nearly all the files in 
clang/lib/Headers. Most of these files are platform specific (e.g. 
`immintrin.h` is x86 specific). A distribution build will have to either 
include all the headers for all the platforms, or not include any headers. For 
example, if a distribution build for `powerpc` includes the 
`clang-resource-headers` target, it will include all the `x86` specific 
headers, even-though the `x86` specific headers cannot be used.

This patch breaks up the `clang-resource-headers` list to a core list and 
platform specific lists. With the patch, a distribution build can now include 
the `ppc-resource-headers` to include the headers applicable to the `powerpc` 
platform.

Specifically, one can now have

  cmake ... LLVM_DISTRIBUTION_COMPONENTS="clang;ppc-resource-headers" ... 
../llvm

`ninja install-distribution` then installs the powerpc headers.

Similarly, one can do

  cmake ... LLVM_DISTRIBUTION_COMPONENTS="clang;x86-resource-headers" ... 
../llvm

to include headers applicable to the x86 platform in a distribution 
installation.

To implement this behaviour, the patch does two things

1. It breaks up the long files header file list to a core list and platform 
specific lists.
2. It adds numerous platform specific installation targets.

This may or may not be a good way to break up the long header list to add new 
targets, so I am all ears for suggestions/feedback! Also, we may need to add 
other reviewers. May I get some suggestions on that as well?

Thanks so much!


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123498

Files:
  clang/lib/Headers/CMakeLists.txt

Index: clang/lib/Headers/CMakeLists.txt
===================================================================
--- clang/lib/Headers/CMakeLists.txt
+++ clang/lib/Headers/CMakeLists.txt
@@ -1,12 +1,95 @@
-set(files
-  adxintrin.h
-  altivec.h
-  ammintrin.h
-  amxintrin.h
+# core_files list contains the headers shared by all platforms.
+# Please consider adding new platform specific headers
+# to platform specific lists below.
+set(core_files
+  builtins.h
+  float.h
+  inttypes.h
+  iso646.h
+  limits.h
+  module.modulemap
+  stdalign.h
+  stdarg.h
+  stdatomic.h
+  stdbool.h
+  stddef.h
+  __stddef_max_align_t.h
+  stdint.h
+  stdnoreturn.h
+  tgmath.h
+  unwind.h
+  varargs.h
+  )
+
+set(arm_files
   arm_acle.h
   arm_cmse.h
   armintr.h
   arm64intr.h
+  )
+
+set(cuda_files
+  __clang_cuda_builtin_vars.h
+  __clang_cuda_math.h
+  __clang_cuda_cmath.h
+  __clang_cuda_complex_builtins.h
+  __clang_cuda_device_functions.h
+  __clang_cuda_intrinsics.h
+  __clang_cuda_texture_intrinsics.h
+  __clang_cuda_libdevice_declares.h
+  __clang_cuda_math_forward_declares.h
+  __clang_cuda_runtime_wrapper.h
+  )
+
+set(hexagon_files
+  hexagon_circ_brev_intrinsics.h
+  hexagon_protos.h
+  hexagon_types.h
+  hvx_hexagon_protos.h
+  )
+
+set(hip_files
+  __clang_hip_libdevice_declares.h
+  __clang_hip_cmath.h
+  __clang_hip_math.h
+  __clang_hip_runtime_wrapper.h
+  )
+
+set(mips_msa_files
+  msa.h
+  )
+
+set(opencl_files
+  opencl-c.h
+  opencl-c-base.h
+  )
+
+set(ppc_files
+  altivec.h
+  htmintrin.h
+  htmxlintrin.h
+  )
+
+set(systemz_files
+  s390intrin.h
+  vecintrin.h
+  )
+
+set(ve_files
+  velintrin.h
+  velintrin_gen.h
+  velintrin_approx.h
+  )
+
+set(webassembly_files
+  wasm_simd128.h
+  )
+
+set(x86_files
+# Intrinsics
+  ammintrin.h
+  adxintrin.h
+  amxintrin.h
   avx2intrin.h
   avx512bf16intrin.h
   avx512bwintrin.h
@@ -40,67 +123,34 @@
   avxvnniintrin.h
   bmi2intrin.h
   bmiintrin.h
-  builtins.h
-  __clang_cuda_builtin_vars.h
-  __clang_cuda_math.h
-  __clang_cuda_cmath.h
-  __clang_cuda_complex_builtins.h
-  __clang_cuda_device_functions.h
-  __clang_cuda_intrinsics.h
-  __clang_cuda_texture_intrinsics.h
-  __clang_cuda_libdevice_declares.h
-  __clang_cuda_math_forward_declares.h
-  __clang_cuda_runtime_wrapper.h
-  __clang_hip_libdevice_declares.h
-  __clang_hip_cmath.h
-  __clang_hip_math.h
-  __clang_hip_runtime_wrapper.h
   cetintrin.h
-  cet.h
   cldemoteintrin.h
-  clzerointrin.h
-  crc32intrin.h
-  cpuid.h
   clflushoptintrin.h
   clwbintrin.h
+  clzerointrin.h
+  crc32intrin.h
   emmintrin.h
   enqcmdintrin.h
   f16cintrin.h
-  float.h
-  fma4intrin.h
   fmaintrin.h
+  fma4intrin.h
   fxsrintrin.h
   gfniintrin.h
-  hexagon_circ_brev_intrinsics.h
-  hexagon_protos.h
-  hexagon_types.h
-  hvx_hexagon_protos.h
   hresetintrin.h
-  htmintrin.h
-  htmxlintrin.h
   ia32intrin.h
   immintrin.h
-  intrin.h
-  inttypes.h
   invpcidintrin.h
-  iso646.h
   keylockerintrin.h
-  limits.h
   lwpintrin.h
   lzcntintrin.h
   mm3dnow.h
   mmintrin.h
-  mm_malloc.h
-  module.modulemap
   movdirintrin.h
-  msa.h
   mwaitxintrin.h
   nmmintrin.h
-  opencl-c.h
-  opencl-c-base.h
+  pconfigintrin.h
   pkuintrin.h
   pmmintrin.h
-  pconfigintrin.h
   popcntintrin.h
   prfchwintrin.h
   ptwriteintrin.h
@@ -108,30 +158,14 @@
   rtmintrin.h
   serializeintrin.h
   sgxintrin.h
-  s390intrin.h
   shaintrin.h
   smmintrin.h
-  stdalign.h
-  stdarg.h
-  stdatomic.h
-  stdbool.h
-  stddef.h
-  __stddef_max_align_t.h
-  stdint.h
-  stdnoreturn.h
-  tbmintrin.h
-  tgmath.h
   tmmintrin.h
+  tbmintrin.h
   tsxldtrkintrin.h
-  uintrintrin.h
-  unwind.h
-  vadefs.h
   vaesintrin.h
-  varargs.h
-  vecintrin.h
   vpclmulqdqintrin.h
   waitpkgintrin.h
-  wasm_simd128.h
   wbnoinvdintrin.h
   wmmintrin.h
   __wmmintrin_aes.h
@@ -145,9 +179,36 @@
   xsaveoptintrin.h
   xsavesintrin.h
   xtestintrin.h
-  velintrin.h
-  velintrin_gen.h
-  velintrin_approx.h
+  uintrintrin.h
+# others
+  cet.h
+  cpuid.h
+  )
+
+set(windows_only_files
+  intrin.h
+  vadefs.h
+)
+
+set(utility_files
+  mm_malloc.h
+)
+
+set(files
+  ${core_files}
+  ${arm_files}
+  ${cuda_files}
+  ${hexagon_files}
+  ${hip_files}
+  ${mips_msa_files}
+  ${opencl_files}
+  ${ppc_files}
+  ${systemz_files}
+  ${ve_files}
+  ${x86_files}
+  ${webassembly_files}
+  ${windows_only_files}
+  ${utility_files}
   )
 
 set(cuda_wrapper_files
@@ -167,7 +228,6 @@
   ppc_wrappers/bmiintrin.h
   ppc_wrappers/bmi2intrin.h
   ppc_wrappers/immintrin.h
-  ppc_wrappers/tmmintrin.h
   ppc_wrappers/x86intrin.h
   ppc_wrappers/x86gprintrin.h
 )
@@ -238,10 +298,28 @@
   clang_generate_header(-gen-riscv-vector-header riscv_vector.td riscv_vector.h)
 endif()
 
-add_custom_target(clang-resource-headers ALL DEPENDS ${out_files})
-set_target_properties(clang-resource-headers PROPERTIES
-  FOLDER "Misc"
-  RUNTIME_OUTPUT_DIRECTORY "${output_dir}")
+function(add_header_target target_name)
+  add_custom_target(${target_name} ALL DEPENDS ${out_files})
+  set_target_properties(${target_name} PROPERTIES
+    FOLDER "Misc"
+    RUNTIME_OUTPUT_DIRECTORY "${output_dir}")
+endfunction()
+
+add_header_target("clang-resource-headers")
+
+# Architecture/platform specific targets
+add_header_target("arm-resource-headers")
+add_header_target("cuda-resource-headers")
+add_header_target("hexagon-resource-headers")
+add_header_target("hip-resource-headers")
+add_header_target("mips-resource-headers")
+add_header_target("opencl-resource-headers")
+add_header_target("ppc-resource-headers")
+add_header_target("systemz-resource-headers")
+add_header_target("ve-resource-headers")
+add_header_target("webassembly-resource-headers")
+add_header_target("windows-resource-headers")
+add_header_target("x86-resource-headers")
 
 set(header_install_dir lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}/include)
 
@@ -265,8 +343,132 @@
   DESTINATION ${header_install_dir}/openmp_wrappers
   COMPONENT clang-resource-headers)
 
+#############################################################
+# Install rules for architecture/platform specific headers
+# All the targets are subsets of the clang-resource-headers list.
+install(
+  FILES ${core_files} ${arm_files}
+  DESTINATION ${header_install_dir}
+  EXCLUDE_FROM_ALL
+  COMPONENT arm-resource-headers)
+
+install(
+  FILES ${cuda_wrapper_files}
+  DESTINATION ${header_install_dir}/cuda_wrappers
+  EXCLUDE_FROM_ALL
+  COMPONENT cuda-resource-headers)
+
+install(
+  FILES ${core_files} ${cuda_files}
+  DESTINATION ${header_install_dir}
+  EXCLUDE_FROM_ALL
+  COMPONENT cuda-resource-headers)
+
+install(
+  FILES ${core_files} ${hexagon_files}
+  DESTINATION ${header_install_dir}
+  EXCLUDE_FROM_ALL
+  COMPONENT hexagon-resource-headers)
+
+install(
+  FILES ${core_files} ${hip_files}
+  DESTINATION ${header_install_dir}
+  EXCLUDE_FROM_ALL
+  COMPONENT hip-resource-headers)
+
+install(
+  FILES ${core_files} ${mips_msa_files}
+  DESTINATION ${header_install_dir}
+  EXCLUDE_FROM_ALL
+  COMPONENT mips-resource-headers)
+
+install(
+  FILES ${core_files} ${opencl_files}
+  DESTINATION ${header_install_dir}
+  EXCLUDE_FROM_ALL
+  COMPONENT opencl-resource-headers)
+
+install(
+  FILES ${ppc_wrapper_files}
+  DESTINATION ${header_install_dir}/ppc_wrappers
+  EXCLUDE_FROM_ALL
+  COMPONENT ppc-resource-headers)
+
+install(
+  FILES ${core_files} ${ppc_files}
+  DESTINATION ${header_install_dir}
+  EXCLUDE_FROM_ALL
+  COMPONENT ppc-resource-headers)
+
+install(
+  FILES ${core_files} ${systemz_files}
+  DESTINATION ${header_install_dir}
+  EXCLUDE_FROM_ALL
+  COMPONENT systemz-resource-headers)
+
+install(
+  FILES ${core_files} ${ve_files}
+  DESTINATION ${header_install_dir}
+  EXCLUDE_FROM_ALL
+  COMPONENT ve-resource-headers)
+
+install(
+  FILES ${core_files} ${webassembly_files}
+  DESTINATION ${header_install_dir}
+  EXCLUDE_FROM_ALL
+  COMPONENT webassembly-resource-headers)
+
+install(
+  FILES ${core_files} ${windows_files}
+  DESTINATION ${header_install_dir}
+  EXCLUDE_FROM_ALL
+  COMPONENT windows-resource-headers)
+
+install(
+  FILES ${core_files} ${x86_files}
+  DESTINATION ${header_install_dir}
+  EXCLUDE_FROM_ALL
+  COMPONENT x86-resource-headers)
+#############################################################
+
 if (NOT LLVM_ENABLE_IDE)
   add_llvm_install_targets(install-clang-resource-headers
                            DEPENDS clang-resource-headers
                            COMPONENT clang-resource-headers)
+  add_llvm_install_targets(install-arm-resource-headers
+                           DEPENDS arm-resource-headers
+                           COMPONENT arm-resource-headers)
+  add_llvm_install_targets(install-cuda-resource-headers
+                           DEPENDS cuda-resource-headers
+                           COMPONENT cuda-resource-headers)
+  add_llvm_install_targets(install-hexagon-resource-headers
+                           DEPENDS hexagon-resource-headers
+                           COMPONENT hexagon-resource-headers)
+  add_llvm_install_targets(install-hip-resource-headers
+                           DEPENDS hip-resource-headers
+                           COMPONENT hip-resource-headers)
+  add_llvm_install_targets(install-mips-resource-headers
+                           DEPENDS mips-resource-headers
+                           COMPONENT mips-resource-headers)
+  add_llvm_install_targets(install-opencl-resource-headers
+                           DEPENDS opencl-resource-headers
+                           COMPONENT opencl-resource-headers)
+  add_llvm_install_targets(install-ppc-resource-headers
+                           DEPENDS ppc-resource-headers
+                           COMPONENT ppc-resource-headers)
+  add_llvm_install_targets(install-systemz-resource-headers
+                           DEPENDS systemz-resource-headers
+                           COMPONENT systemz-resource-headers)
+  add_llvm_install_targets(install-ve-resource-headers
+                           DEPENDS ve-resource-headers
+                           COMPONENT ve-resource-headers)
+  add_llvm_install_targets(install-x86-resource-headers
+                           DEPENDS x86-resource-headers
+                           COMPONENT x86-resource-headers)
+  add_llvm_install_targets(install-webassembly-resource-headers
+                           DEPENDS webassembly-resource-headers
+                           COMPONENT webassembly-resource-headers)
+  add_llvm_install_targets(install-windows-resource-headers
+                           DEPENDS window-resource-headers
+                           COMPONENT windows-resource-headers)
 endif()
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to