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] Add proxy header math_macros.h. #87598

Merged
merged 7 commits into from
Apr 5, 2024
Merged

[libc] Add proxy header math_macros.h. #87598

merged 7 commits into from
Apr 5, 2024

Conversation

lntue
Copy link
Contributor

@lntue lntue commented Apr 4, 2024

Context: #87017

  • Add proxy header libc/hdr/math_macros.h that will:
    • include <math.h> in overlay mode,
    • include "include/llvm-libc-macros/math-macros.h" in full build mode.
  • Its corresponding CMake target libc.hdr.math_macros will only depend on libc.include.math and libc.include.llvm-libc-macros.math_macros in full build mode.
  • Replace all #include "include/llvm-libc-macros/math-macros.h" with #include "hdr/math_macros.h".
  • Add dependency to libc.hdr.math_macros CMake target when using add_fp_unittest.
  • Update the remaining dependency.
  • Update bazel overlay: add libc:hdr_math_macros target, and replacing all dependency on libc:llvm_libc_macros_math_macros with libc:hdr_math_macros.

@lntue lntue requested a review from rupprecht as a code owner April 4, 2024 05:24
@llvmbot llvmbot added libc bazel "Peripheral" support tier build system: utils/bazel labels Apr 4, 2024
@llvmbot
Copy link

llvmbot commented Apr 4, 2024

@llvm/pr-subscribers-libc

Author: None (lntue)

Changes

Context: #87017

  • Add proxy header libc/hdr/math_macros.h that will:
    • include &lt;math.h&gt; in overlay mode,
    • include "include/llvm-libc-macros/math-macros.h" in full build mode.
  • Its corresponding CMake target libc.hdr.math_macros will only depend on libc.include.math and libc.include.llvm-libc-macros.math_macros in full build mode.
  • Replace all #include "include/llvm-libc-macros/math-macros.h" with #include "hdr/math_macros.h".
  • Add dependency to libc.hdr.math_macros CMake target when using add_fp_unittest.
  • Update the remaining dependency.
  • Update bazel overlay: add libc:hdr_math_macros target, and replacing all dependency on libc:llvm_libc_macros_math_macros with libc:hdr_math_macros.

Patch is 117.25 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/87598.diff

143 Files Affected:

  • (modified) libc/CMakeLists.txt (+1)
  • (modified) libc/fuzzing/math/CMakeLists.txt (+1)
  • (modified) libc/fuzzing/math/RemQuoDiff.h (+1-1)
  • (modified) libc/fuzzing/stdlib/CMakeLists.txt (+1)
  • (modified) libc/fuzzing/stdlib/strtofloat_fuzz.cpp (+1-1)
  • (added) libc/hdr/CMakeLists.txt (+33)
  • (added) libc/hdr/math_macros.h (+22)
  • (modified) libc/include/llvm-libc-macros/math-macros.h (+4-4)
  • (modified) libc/src/__support/FPUtil/CMakeLists.txt (+3-4)
  • (modified) libc/src/__support/FPUtil/FEnvImpl.h (+1-1)
  • (modified) libc/src/__support/FPUtil/ManipulationFunctions.h (+1-1)
  • (modified) libc/src/__support/FPUtil/NearestIntegerOperations.h (+1-1)
  • (modified) libc/src/math/generic/CMakeLists.txt (+1-16)
  • (modified) libc/src/math/generic/math_utils.h (+1-1)
  • (modified) libc/test/CMakeLists.txt (+2-4)
  • (modified) libc/test/UnitTest/FPMatcher.h (+1-1)
  • (modified) libc/test/src/CMakeLists.txt (+7-1)
  • (modified) libc/test/src/__support/uint_test.cpp (+1-1)
  • (modified) libc/test/src/math/CMakeLists.txt (-88)
  • (modified) libc/test/src/math/CeilTest.h (+1-1)
  • (modified) libc/test/src/math/CopySignTest.h (+1-1)
  • (modified) libc/test/src/math/FAbsTest.h (+1-1)
  • (modified) libc/test/src/math/FDimTest.h (+1-1)
  • (modified) libc/test/src/math/FMaxTest.h (+1-1)
  • (modified) libc/test/src/math/FMinTest.h (+1-1)
  • (modified) libc/test/src/math/FModTest.h (+1-1)
  • (modified) libc/test/src/math/FloorTest.h (+1-1)
  • (modified) libc/test/src/math/FrexpTest.h (+1-1)
  • (modified) libc/test/src/math/HypotTest.h (+1-1)
  • (modified) libc/test/src/math/ILogbTest.h (+1-1)
  • (modified) libc/test/src/math/LdExpTest.h (+1-1)
  • (modified) libc/test/src/math/LogbTest.h (+1-1)
  • (modified) libc/test/src/math/ModfTest.h (+1-1)
  • (modified) libc/test/src/math/NextAfterTest.h (+1-1)
  • (modified) libc/test/src/math/RIntTest.h (+1-1)
  • (modified) libc/test/src/math/RemQuoTest.h (+1-1)
  • (modified) libc/test/src/math/RoundTest.h (+1-1)
  • (modified) libc/test/src/math/RoundToIntegerTest.h (+1-1)
  • (modified) libc/test/src/math/SqrtTest.h (+1-1)
  • (modified) libc/test/src/math/TruncTest.h (+1-1)
  • (modified) libc/test/src/math/acosf_test.cpp (+1-1)
  • (modified) libc/test/src/math/acoshf_test.cpp (+1-1)
  • (modified) libc/test/src/math/asinf_test.cpp (+1-1)
  • (modified) libc/test/src/math/asinhf_test.cpp (+1-1)
  • (modified) libc/test/src/math/atan2f_test.cpp (+1-1)
  • (modified) libc/test/src/math/atanf_test.cpp (+1-1)
  • (modified) libc/test/src/math/atanhf_test.cpp (+1-1)
  • (modified) libc/test/src/math/cos_test.cpp (+1-1)
  • (modified) libc/test/src/math/cosf_test.cpp (+1-1)
  • (modified) libc/test/src/math/coshf_test.cpp (+1-1)
  • (modified) libc/test/src/math/erff_test.cpp (+1-1)
  • (modified) libc/test/src/math/exhaustive/CMakeLists.txt (-24)
  • (modified) libc/test/src/math/exp10_test.cpp (+1-1)
  • (modified) libc/test/src/math/exp10f_test.cpp (+1-1)
  • (modified) libc/test/src/math/exp2_test.cpp (+1-1)
  • (modified) libc/test/src/math/exp2f_test.cpp (+1-1)
  • (modified) libc/test/src/math/exp_test.cpp (+1-1)
  • (modified) libc/test/src/math/expf_test.cpp (+1-1)
  • (modified) libc/test/src/math/explogxf_test.cpp (+1-1)
  • (modified) libc/test/src/math/expm1_test.cpp (+1-1)
  • (modified) libc/test/src/math/expm1f_test.cpp (+1-1)
  • (modified) libc/test/src/math/fdim_test.cpp (+1-1)
  • (modified) libc/test/src/math/fdimf_test.cpp (+1-1)
  • (modified) libc/test/src/math/fdiml_test.cpp (+1-1)
  • (modified) libc/test/src/math/generic/CMakeLists.txt (-3)
  • (modified) libc/test/src/math/ilogb_test.cpp (+1-1)
  • (modified) libc/test/src/math/ilogbf_test.cpp (+1-1)
  • (modified) libc/test/src/math/ilogbl_test.cpp (+1-1)
  • (modified) libc/test/src/math/log10_test.cpp (+1-1)
  • (modified) libc/test/src/math/log10f_test.cpp (+1-1)
  • (modified) libc/test/src/math/log1p_test.cpp (+1-1)
  • (modified) libc/test/src/math/log1pf_test.cpp (+1-1)
  • (modified) libc/test/src/math/log2_test.cpp (+1-1)
  • (modified) libc/test/src/math/log2f_test.cpp (+1-1)
  • (modified) libc/test/src/math/log_test.cpp (+1-1)
  • (modified) libc/test/src/math/logf_test.cpp (+1-1)
  • (modified) libc/test/src/math/powf_test.cpp (+1-1)
  • (modified) libc/test/src/math/sin_test.cpp (+1-1)
  • (modified) libc/test/src/math/sincosf_test.cpp (+1-1)
  • (modified) libc/test/src/math/sinf_test.cpp (+1-1)
  • (modified) libc/test/src/math/sinhf_test.cpp (+1-1)
  • (modified) libc/test/src/math/smoke/CMakeLists.txt (-102)
  • (modified) libc/test/src/math/smoke/CanonicalizeTest.h (+1-1)
  • (modified) libc/test/src/math/smoke/CeilTest.h (+1-1)
  • (modified) libc/test/src/math/smoke/CopySignTest.h (+1-1)
  • (modified) libc/test/src/math/smoke/FAbsTest.h (+1-1)
  • (modified) libc/test/src/math/smoke/FModTest.h (+1-1)
  • (modified) libc/test/src/math/smoke/FloorTest.h (+1-1)
  • (modified) libc/test/src/math/smoke/HypotTest.h (+1-1)
  • (modified) libc/test/src/math/smoke/ModfTest.h (+1-1)
  • (modified) libc/test/src/math/smoke/NextAfterTest.h (+1-1)
  • (modified) libc/test/src/math/smoke/NextTowardTest.h (+1-1)
  • (modified) libc/test/src/math/smoke/RIntTest.h (+1-1)
  • (modified) libc/test/src/math/smoke/RemQuoTest.h (+1-1)
  • (modified) libc/test/src/math/smoke/RoundTest.h (+1-1)
  • (modified) libc/test/src/math/smoke/RoundToIntegerTest.h (+1-1)
  • (modified) libc/test/src/math/smoke/SqrtTest.h (+1-1)
  • (modified) libc/test/src/math/smoke/TruncTest.h (+1-1)
  • (modified) libc/test/src/math/smoke/acosf_test.cpp (+1-1)
  • (modified) libc/test/src/math/smoke/acoshf_test.cpp (+1-1)
  • (modified) libc/test/src/math/smoke/asinf_test.cpp (+1-1)
  • (modified) libc/test/src/math/smoke/asinhf_test.cpp (+1-1)
  • (modified) libc/test/src/math/smoke/atan2f_test.cpp (+1-1)
  • (modified) libc/test/src/math/smoke/atanf_test.cpp (+1-1)
  • (modified) libc/test/src/math/smoke/atanhf_test.cpp (+1-1)
  • (modified) libc/test/src/math/smoke/cosf_test.cpp (+1-1)
  • (modified) libc/test/src/math/smoke/coshf_test.cpp (+1-1)
  • (modified) libc/test/src/math/smoke/erff_test.cpp (+1-1)
  • (modified) libc/test/src/math/smoke/exp10_test.cpp (+1-1)
  • (modified) libc/test/src/math/smoke/exp10f_test.cpp (+1-1)
  • (modified) libc/test/src/math/smoke/exp2_test.cpp (+1-1)
  • (modified) libc/test/src/math/smoke/exp2f_test.cpp (+1-1)
  • (modified) libc/test/src/math/smoke/exp_test.cpp (+1-1)
  • (modified) libc/test/src/math/smoke/expf_test.cpp (+1-1)
  • (modified) libc/test/src/math/smoke/expm1_test.cpp (+1-1)
  • (modified) libc/test/src/math/smoke/expm1f_test.cpp (+1-1)
  • (modified) libc/test/src/math/smoke/log10_test.cpp (+1-1)
  • (modified) libc/test/src/math/smoke/log10f_test.cpp (+1-1)
  • (modified) libc/test/src/math/smoke/log1p_test.cpp (+1-1)
  • (modified) libc/test/src/math/smoke/log1pf_test.cpp (+1-1)
  • (modified) libc/test/src/math/smoke/log2_test.cpp (+1-1)
  • (modified) libc/test/src/math/smoke/log2f_test.cpp (+1-1)
  • (modified) libc/test/src/math/smoke/log_test.cpp (+1-1)
  • (modified) libc/test/src/math/smoke/logf_test.cpp (+1-1)
  • (modified) libc/test/src/math/smoke/powf_test.cpp (+1-1)
  • (modified) libc/test/src/math/smoke/sincosf_test.cpp (+1-1)
  • (modified) libc/test/src/math/smoke/sinf_test.cpp (+1-1)
  • (modified) libc/test/src/math/smoke/sinhf_test.cpp (+1-1)
  • (modified) libc/test/src/math/smoke/tanf_test.cpp (+1-1)
  • (modified) libc/test/src/math/smoke/tanhf_test.cpp (+1-1)
  • (modified) libc/test/src/math/tan_test.cpp (+1-1)
  • (modified) libc/test/src/math/tanf_test.cpp (+1-1)
  • (modified) libc/test/src/math/tanhf_test.cpp (+1-1)
  • (modified) libc/test/src/sys/random/linux/CMakeLists.txt (-1)
  • (modified) libc/test/utils/FPUtil/CMakeLists.txt (+1-1)
  • (modified) libc/test/utils/FPUtil/x86_long_double_test.cpp (+1-1)
  • (modified) libc/utils/MPFRWrapper/MPFRUtils.cpp (+1-1)
  • (modified) utils/bazel/llvm-project-overlay/libc/BUILD.bazel (+12-5)
  • (modified) utils/bazel/llvm-project-overlay/libc/test/UnitTest/BUILD.bazel (+1-1)
  • (modified) utils/bazel/llvm-project-overlay/libc/test/src/__support/BUILD.bazel (+1-1)
  • (modified) utils/bazel/llvm-project-overlay/libc/test/src/math/BUILD.bazel (+7-7)
  • (modified) utils/bazel/llvm-project-overlay/libc/test/src/math/libc_math_test_rules.bzl (+1-1)
  • (modified) utils/bazel/llvm-project-overlay/libc/utils/MPFRWrapper/BUILD.bazel (+1-1)
diff --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt
index a0d79858a896ad..175efd89d67e6d 100644
--- a/libc/CMakeLists.txt
+++ b/libc/CMakeLists.txt
@@ -381,6 +381,7 @@ endforeach()
 
 add_subdirectory(include)
 add_subdirectory(config)
+add_subdirectory(hdr)
 add_subdirectory(src)
 add_subdirectory(utils)
 
diff --git a/libc/fuzzing/math/CMakeLists.txt b/libc/fuzzing/math/CMakeLists.txt
index 86c864083d206b..6990a04922a5cf 100644
--- a/libc/fuzzing/math/CMakeLists.txt
+++ b/libc/fuzzing/math/CMakeLists.txt
@@ -8,6 +8,7 @@ add_libc_fuzzer(
     SingleInputSingleOutputDiff.h
     TwoInputSingleOutputDiff.h
   DEPENDS
+    libc.hdr.math_macros
     libc.src.math.ceil
     libc.src.math.ceilf
     libc.src.math.ceill
diff --git a/libc/fuzzing/math/RemQuoDiff.h b/libc/fuzzing/math/RemQuoDiff.h
index 95a9866f29dbbe..84a6a24ce52719 100644
--- a/libc/fuzzing/math/RemQuoDiff.h
+++ b/libc/fuzzing/math/RemQuoDiff.h
@@ -11,7 +11,7 @@
 
 #include "src/__support/FPUtil/FPBits.h"
 
-#include "include/llvm-libc-macros/math-macros.h"
+#include "hdr/math_macros.h"
 #include <stddef.h>
 #include <stdint.h>
 
diff --git a/libc/fuzzing/stdlib/CMakeLists.txt b/libc/fuzzing/stdlib/CMakeLists.txt
index 711b0fd9820f93..204bc619318da2 100644
--- a/libc/fuzzing/stdlib/CMakeLists.txt
+++ b/libc/fuzzing/stdlib/CMakeLists.txt
@@ -22,6 +22,7 @@ add_libc_fuzzer(
   SRCS
     strtofloat_fuzz.cpp
   DEPENDS
+    libc.hdr.math_macros
     libc.src.stdlib.atof
     libc.src.stdlib.strtof
     libc.src.stdlib.strtod
diff --git a/libc/fuzzing/stdlib/strtofloat_fuzz.cpp b/libc/fuzzing/stdlib/strtofloat_fuzz.cpp
index b000321854d16d..c158162ba6238e 100644
--- a/libc/fuzzing/stdlib/strtofloat_fuzz.cpp
+++ b/libc/fuzzing/stdlib/strtofloat_fuzz.cpp
@@ -16,7 +16,7 @@
 
 #include "src/__support/FPUtil/FPBits.h"
 
-#include "include/llvm-libc-macros/math-macros.h"
+#include "hdr/math_macros.h"
 #include <stddef.h>
 #include <stdint.h>
 
diff --git a/libc/hdr/CMakeLists.txt b/libc/hdr/CMakeLists.txt
new file mode 100644
index 00000000000000..1d3eb9d5240ab9
--- /dev/null
+++ b/libc/hdr/CMakeLists.txt
@@ -0,0 +1,33 @@
+function(add_proxy_header_library target_name)
+  cmake_parse_arguments(
+    "ADD_PROXY_HEADER"
+    "" # Optional arguments
+    "" # Single value arguments
+    "DEPENDS;FULL_BUILD_DEPENDS" # Multi-value arguments
+    ${ARGN}
+  )
+
+  set(deps "")
+  if(ADD_PROXY_HEADER_DEPENDS)
+    list(APPEND deps ${ADD_PROXY_HEADER_DEPENDS})
+  endif()
+
+  if(LLVM_LIBC_FULL_BUILD AND ADD_PROXY_HEADER_FULL_BUILD_DEPENDS)
+    list(APPEND deps ${ADD_PROXY_HEADER_FULL_BUILD_DEPENDS})
+  endif()
+
+  add_header_library(
+    ${target_name}
+    ${ADD_PROXY_HEADER_UNPARSED_ARGUMENTS}
+    DEPENDS ${deps}
+  )
+endfunction()
+
+add_proxy_header_library(
+  math_macros
+  HDRS
+    math_macros.h
+  FULL_BUILD_DEPENDS
+    libc.include.llvm-libc-macros.math_macros
+    libc.include.math
+)
diff --git a/libc/hdr/math_macros.h b/libc/hdr/math_macros.h
new file mode 100644
index 00000000000000..008d00354b4b0e
--- /dev/null
+++ b/libc/hdr/math_macros.h
@@ -0,0 +1,22 @@
+//===-- Definition of macros from math.h ----------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_HDR_MATH_MACROS_H
+#define LLVM_LIBC_HDR_MATH_MACROS_H
+
+#ifdef LLVM_LIBC_FULL_BUILD
+
+#include "include/llvm-libc-macros/math-macros.h"
+
+#else // Overlay mode
+
+#include <math.h>
+
+#endif // LLVM_LIBC_FULL_BUILD
+
+#endif // LLVM_LIBC_HDR_MATH_MACROS_H
diff --git a/libc/include/llvm-libc-macros/math-macros.h b/libc/include/llvm-libc-macros/math-macros.h
index 1497e32044e975..3ee32e331ed27c 100644
--- a/libc/include/llvm-libc-macros/math-macros.h
+++ b/libc/include/llvm-libc-macros/math-macros.h
@@ -30,12 +30,12 @@
 #define INFINITY __builtin_inf()
 #define NAN __builtin_nanf("")
 
-#define FP_ILOGB0 (-INT_MAX - 1)
-#define FP_LLOGB0 (-LONG_MAX - 1)
+#define FP_ILOGB0 INT_MIN
+#define FP_LLOGB0 LONG_MIN
 
 #ifdef __FP_LOGBNAN_MIN
-#define FP_ILOGBNAN (-INT_MAX - 1)
-#define FP_LLOGBNAN (-LONG_MAX - 1)
+#define FP_ILOGBNAN INT_MIN
+#define FP_LLOGBNAN LONG_MIN
 #else
 #define FP_ILOGBNAN INT_MAX
 #define FP_LLOGBNAN LONG_MAX
diff --git a/libc/src/__support/FPUtil/CMakeLists.txt b/libc/src/__support/FPUtil/CMakeLists.txt
index ff155a19758d20..1af236ed9d6bc1 100644
--- a/libc/src/__support/FPUtil/CMakeLists.txt
+++ b/libc/src/__support/FPUtil/CMakeLists.txt
@@ -4,7 +4,7 @@ add_header_library(
     FEnvImpl.h
   DEPENDS
     libc.include.fenv
-    libc.include.math
+    libc.hdr.math_macros
     libc.src.__support.macros.attributes
     libc.src.errno.errno
 )
@@ -15,7 +15,6 @@ add_header_library(
     rounding_mode.h
   DEPENDS
     libc.include.fenv
-    libc.include.math
     libc.src.__support.macros.attributes
     libc.src.__support.macros.properties.architectures
     libc.src.__support.macros.sanitizer
@@ -59,9 +58,9 @@ add_header_library(
     .fp_bits
     .fenv_impl
     .rounding_mode
+    libc.hdr.math_macros
     libc.src.__support.CPP.type_traits
     libc.src.__support.common
-    libc.include.math
     libc.src.errno.errno
 )
 
@@ -216,12 +215,12 @@ add_header_library(
     .dyadic_float
     .nearest_integer_operations
     .normal_float
+    libc.hdr.math_macros
     libc.src.__support.CPP.bit
     libc.src.__support.CPP.limits
     libc.src.__support.CPP.type_traits
     libc.src.__support.common
     libc.src.__support.macros.optimization
-    libc.include.math
     libc.src.errno.errno
 )
 
diff --git a/libc/src/__support/FPUtil/FEnvImpl.h b/libc/src/__support/FPUtil/FEnvImpl.h
index 6086d5d3de2dca..4be1a57f0f4b38 100644
--- a/libc/src/__support/FPUtil/FEnvImpl.h
+++ b/libc/src/__support/FPUtil/FEnvImpl.h
@@ -9,7 +9,7 @@
 #ifndef LLVM_LIBC_SRC___SUPPORT_FPUTIL_FENVIMPL_H
 #define LLVM_LIBC_SRC___SUPPORT_FPUTIL_FENVIMPL_H
 
-#include "include/llvm-libc-macros/math-macros.h"
+#include "hdr/math_macros.h"
 #include "src/__support/macros/attributes.h" // LIBC_INLINE
 #include "src/__support/macros/properties/architectures.h"
 #include "src/errno/libc_errno.h"
diff --git a/libc/src/__support/FPUtil/ManipulationFunctions.h b/libc/src/__support/FPUtil/ManipulationFunctions.h
index 2c90b4888c2e5d..a289c2ef70467b 100644
--- a/libc/src/__support/FPUtil/ManipulationFunctions.h
+++ b/libc/src/__support/FPUtil/ManipulationFunctions.h
@@ -15,7 +15,7 @@
 #include "dyadic_float.h"
 #include "rounding_mode.h"
 
-#include "include/llvm-libc-macros/math-macros.h"
+#include "hdr/math_macros.h"
 #include "src/__support/CPP/bit.h"
 #include "src/__support/CPP/limits.h" // INT_MAX, INT_MIN
 #include "src/__support/CPP/type_traits.h"
diff --git a/libc/src/__support/FPUtil/NearestIntegerOperations.h b/libc/src/__support/FPUtil/NearestIntegerOperations.h
index 6b28e7ffb387b5..4645ab0b5350be 100644
--- a/libc/src/__support/FPUtil/NearestIntegerOperations.h
+++ b/libc/src/__support/FPUtil/NearestIntegerOperations.h
@@ -13,7 +13,7 @@
 #include "FPBits.h"
 #include "rounding_mode.h"
 
-#include "include/llvm-libc-macros/math-macros.h"
+#include "hdr/math_macros.h"
 #include "src/__support/CPP/type_traits.h"
 #include "src/__support/common.h"
 
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index b164d33e204b1a..02760237d4f7b3 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -102,8 +102,8 @@ add_object_library(
   HDRS
     math_utils.h
   DEPENDS
+    libc.hdr.math_macros
     libc.include.errno
-    libc.include.math
     libc.src.errno.errno
 )
 
@@ -139,7 +139,6 @@ add_entrypoint_object(
     ../cosf.h
   DEPENDS
     .sincosf_utils
-    libc.include.math
     libc.src.errno.errno
     libc.src.__support.FPUtil.basic_operations
     libc.src.__support.FPUtil.fenv_impl
@@ -162,7 +161,6 @@ add_entrypoint_object(
   DEPENDS
     .range_reduction
     .sincosf_utils
-    libc.include.math
     libc.src.errno.errno
     libc.src.__support.FPUtil.basic_operations
     libc.src.__support.FPUtil.fenv_impl
@@ -185,7 +183,6 @@ add_entrypoint_object(
   DEPENDS
     .range_reduction
     .sincosf_utils
-    libc.include.math
     libc.src.errno.errno
     libc.src.__support.FPUtil.fenv_impl
     libc.src.__support.FPUtil.fp_bits
@@ -207,7 +204,6 @@ add_entrypoint_object(
   DEPENDS
     .range_reduction
     .sincosf_utils
-    libc.include.math
     libc.src.errno.errno
     libc.src.__support.FPUtil.fenv_impl
     libc.src.__support.FPUtil.fenv_impl
@@ -721,7 +717,6 @@ add_entrypoint_object(
     libc.src.__support.FPUtil.multiply_add
     libc.src.__support.FPUtil.polyeval
     libc.src.__support.macros.optimization
-    libc.include.math
   COMPILE_OPTIONS
     -O3
 )
@@ -736,7 +731,6 @@ add_entrypoint_object(
     .common_constants
     .explogxf
     libc.include.errno
-    libc.include.math
     libc.src.__support.CPP.bit
     libc.src.__support.CPP.optional
     libc.src.__support.FPUtil.dyadic_float
@@ -772,7 +766,6 @@ add_entrypoint_object(
     libc.src.__support.macros.optimization
     libc.include.errno
     libc.src.errno.errno
-    libc.include.math
   COMPILE_OPTIONS
     -O3
 )
@@ -787,7 +780,6 @@ add_entrypoint_object(
     .common_constants
     .explogxf
     libc.include.errno
-    libc.include.math
     libc.src.__support.CPP.bit
     libc.src.__support.CPP.optional
     libc.src.__support.FPUtil.dyadic_float
@@ -822,7 +814,6 @@ add_header_library(
     libc.src.__support.common
     libc.include.errno
     libc.src.errno.errno
-    libc.include.math
 )
 
 add_entrypoint_object(
@@ -847,7 +838,6 @@ add_entrypoint_object(
     .common_constants
     .explogxf
     libc.include.errno
-    libc.include.math
     libc.src.__support.CPP.bit
     libc.src.__support.CPP.optional
     libc.src.__support.FPUtil.dyadic_float
@@ -881,7 +871,6 @@ add_header_library(
     libc.src.__support.common
     libc.include.errno
     libc.src.errno.errno
-    libc.include.math
   COMPILE_OPTIONS
     -O3
 )
@@ -908,7 +897,6 @@ add_entrypoint_object(
     .common_constants
     .explogxf
     libc.include.errno
-    libc.include.math
     libc.src.__support.CPP.bit
     libc.src.__support.CPP.optional
     libc.src.__support.FPUtil.dyadic_float
@@ -944,7 +932,6 @@ add_entrypoint_object(
     libc.src.__support.macros.optimization
     libc.include.errno
     libc.src.errno.errno
-    libc.include.math
   COMPILE_OPTIONS
     -O3
 )
@@ -961,7 +948,6 @@ add_entrypoint_object(
     .exp2f_impl
     .explogxf
     libc.include.errno
-    libc.include.math
     libc.src.__support.CPP.bit
     libc.src.__support.CPP.optional
     libc.src.__support.FPUtil.fenv_impl
@@ -2685,7 +2671,6 @@ add_object_library(
     libc.src.__support.common
     libc.include.errno
     libc.src.errno.errno
-    libc.include.math
   COMPILE_OPTIONS
     -O3
 )
diff --git a/libc/src/math/generic/math_utils.h b/libc/src/math/generic/math_utils.h
index cced761fc8c822..3ddfeccfd64837 100644
--- a/libc/src/math/generic/math_utils.h
+++ b/libc/src/math/generic/math_utils.h
@@ -9,7 +9,7 @@
 #ifndef LLVM_LIBC_SRC_MATH_GENERIC_MATH_UTILS_H
 #define LLVM_LIBC_SRC_MATH_GENERIC_MATH_UTILS_H
 
-#include "include/llvm-libc-macros/math-macros.h"
+#include "hdr/math_macros.h"
 #include "src/__support/CPP/bit.h"
 #include "src/__support/CPP/type_traits.h"
 #include "src/__support/common.h"
diff --git a/libc/test/CMakeLists.txt b/libc/test/CMakeLists.txt
index 745a9a04b4af82..5e26a1000633b7 100644
--- a/libc/test/CMakeLists.txt
+++ b/libc/test/CMakeLists.txt
@@ -18,10 +18,6 @@ add_subdirectory(include)
 add_subdirectory(src)
 add_subdirectory(utils)
 
-if(LLVM_LIBC_FULL_BUILD AND NOT LIBC_TARGET_OS_IS_BAREMETAL)
-  add_subdirectory(IntegrationTest)
-endif()
-
 if(NOT LLVM_LIBC_FULL_BUILD)
   return()
 endif()
@@ -31,4 +27,6 @@ if(NOT ${LIBC_TARGET_OS} STREQUAL "linux" AND
   # Integration tests are currently only available for linux and the GPU.
   return()
 endif()
+
+add_subdirectory(IntegrationTest)
 add_subdirectory(integration)
diff --git a/libc/test/UnitTest/FPMatcher.h b/libc/test/UnitTest/FPMatcher.h
index f4553eac5c8a57..a76e0b8ef6f6f0 100644
--- a/libc/test/UnitTest/FPMatcher.h
+++ b/libc/test/UnitTest/FPMatcher.h
@@ -18,7 +18,7 @@
 #include "test/UnitTest/StringUtils.h"
 #include "test/UnitTest/Test.h"
 
-#include "include/llvm-libc-macros/math-macros.h"
+#include "hdr/math_macros.h"
 
 namespace LIBC_NAMESPACE {
 namespace testing {
diff --git a/libc/test/src/CMakeLists.txt b/libc/test/src/CMakeLists.txt
index f70ffda3f700e5..95f1768c96aac3 100644
--- a/libc/test/src/CMakeLists.txt
+++ b/libc/test/src/CMakeLists.txt
@@ -3,7 +3,7 @@ function(add_fp_unittest name)
     "MATH_UNITTEST"
     "NEED_MPFR;UNIT_TEST_ONLY;HERMETIC_TEST_ONLY" # Optional arguments
     "" # Single value arguments
-    "LINK_LIBRARIES" # Multi-value arguments
+    "LINK_LIBRARIES;DEPENDS" # Multi-value arguments
     ${ARGN}
   )
 
@@ -28,11 +28,17 @@ function(add_fp_unittest name)
   endif()
   list(APPEND MATH_UNITTEST_LINK_LIBRARIES LibcFPTestHelpers)
 
+  set(deps libc.hdr.math_macros)
+  if(MATH_UNITTEST_DEPENDS)
+    list(APPEND deps ${MATH_UNITTEST_DEPENDS})
+  endif()
+
   add_libc_test(
     ${name}
     ${test_type}
     LINK_LIBRARIES "${MATH_UNITTEST_LINK_LIBRARIES}"
     "${MATH_UNITTEST_UNPARSED_ARGUMENTS}"
+    DEPENDS "${deps}"
   )
 endfunction(add_fp_unittest)
 
diff --git a/libc/test/src/__support/uint_test.cpp b/libc/test/src/__support/uint_test.cpp
index 5764324ca28815..de56428e6bb4b0 100644
--- a/libc/test/src/__support/uint_test.cpp
+++ b/libc/test/src/__support/uint_test.cpp
@@ -10,7 +10,7 @@
 #include "src/__support/UInt.h"
 #include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_INT128
 
-#include "include/llvm-libc-macros/math-macros.h" // HUGE_VALF, HUGE_VALF
+#include "hdr/math_macros.h" // HUGE_VALF, HUGE_VALF
 #include "test/UnitTest/Test.h"
 
 namespace LIBC_NAMESPACE {
diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt
index f8f0f8ba7b6f63..fa3e7f58309050 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -108,7 +108,6 @@ add_fp_unittest(
   HDRS
     FAbsTest.h
   DEPENDS
-    libc.include.math
     libc.src.math.fabs
     libc.src.__support.FPUtil.fp_bits
 )
@@ -123,7 +122,6 @@ add_fp_unittest(
   HDRS
     FAbsTest.h
   DEPENDS
-    libc.include.math
     libc.src.math.fabsf
     libc.src.__support.FPUtil.fp_bits
 )
@@ -138,7 +136,6 @@ add_fp_unittest(
   HDRS
     FAbsTest.h
   DEPENDS
-    libc.include.math
     libc.src.math.fabsl
     libc.src.__support.FPUtil.fp_bits
 )
@@ -153,7 +150,6 @@ add_fp_unittest(
   HDRS
     TruncTest.h
   DEPENDS
-    libc.include.math
     libc.src.math.trunc
     libc.src.__support.FPUtil.fp_bits
 )
@@ -168,7 +164,6 @@ add_fp_unittest(
   HDRS
     TruncTest.h
   DEPENDS
-    libc.include.math
     libc.src.math.truncf
     libc.src.__support.FPUtil.fp_bits
 )
@@ -183,7 +178,6 @@ add_fp_unittest(
   HDRS
     TruncTest.h
   DEPENDS
-    libc.include.math
     libc.src.math.truncl
     libc.src.__support.FPUtil.fp_bits
 )
@@ -198,7 +192,6 @@ add_fp_unittest(
   HDRS
     CeilTest.h
   DEPENDS
-    libc.include.math
     libc.src.math.ceil
     libc.src.__support.FPUtil.fp_bits
 )
@@ -213,7 +206,6 @@ add_fp_unittest(
   HDRS
     CeilTest.h
   DEPENDS
-    libc.include.math
     libc.src.math.ceilf
     libc.src.__support.FPUtil.fp_bits
 )
@@ -228,7 +220,6 @@ add_fp_unittest(
   HDRS
     CeilTest.h
   DEPENDS
-    libc.include.math
     libc.src.math.ceill
     libc.src.__support.FPUtil.fp_bits
 )
@@ -243,7 +234,6 @@ add_fp_unittest(
   HDRS
     FloorTest.h
   DEPENDS
-    libc.include.math
     libc.src.math.floor
     libc.src.__support.FPUtil.fp_bits
 )
@@ -258,7 +248,6 @@ add_fp_unittest(
   HDRS
     FloorTest.h
   DEPENDS
-    libc.include.math
     libc.src.math.floorf
     libc.src.__support.FPUtil.fp_bits
 )
@@ -273,7 +262,6 @@ add_fp_unittest(
   HDRS
     FloorTest.h
   DEPENDS
-    libc.include.math
     libc.src.math.floorl
     libc.src.__support.FPUtil.fp_bits
 )
@@ -288,7 +276,6 @@ add_fp_unittest(
   HDRS
     RoundTest.h
   DEPENDS
-    libc.include.math
     libc.src.math.round
     libc.src.__support.FPUtil.fp_bits
 )
@@ -303,7 +290,6 @@ add_fp_unittest(
   HDRS
     RoundTest.h
   DEPENDS
-    libc.include.math
     libc.src.math.roundf
     libc.src.__support.FPUtil.fp_bits
 )
@@ -318,7 +304,6 @@ add_fp_unittest(
   HDRS
     RoundTest.h
   DEPENDS
-    libc.include.math
     libc.src.math.roundl
     libc.src.__support.FPUtil.fp_bits
 )
@@ -333,7 +318,6 @@ add_fp_unittest(
   HDRS
     RoundToIntegerTest.h
   DEPENDS
-    libc.include.math
     libc.src.errno.errno
     libc.src.fenv.feclearexcept
     libc.src.fenv.feraiseexcept
@@ -352,7 +336,6 @@ add_fp_unittest(
   HDRS
     RoundToIntegerTest.h
   DEPENDS
-    libc.include.math
     libc.src.errno.errno
     libc.src.fenv.feclearexcept
     libc.src.fenv.feraiseexcept
@@ -371,7 +354,6 @@ add_fp_unittest(
   HDRS
     RoundToIntegerTest.h
   DEPENDS
-    libc.include.math
     libc.src.errno.errno
     libc.src.fenv.feclearexcept
     libc.src.fenv.feraiseexcept
@@ -390,7 +372,6 @@ add_fp_unittest(
   HDRS
     RoundToIntegerTest.h
   DEPENDS
-    libc.include.math
     libc.src.errno.errno
     libc.src.fenv.feclearexcept
     libc.src.fenv.feraiseexcept
@@ -409,7 +390,6 @@ add_fp_unittest(
   HDRS
     RoundToIntegerTest.h
   DEPENDS
-    libc.include.math
     libc.src.errno.errno
     libc.src.fenv.feclearexcept
     libc.src.fenv.feraiseexcept
@@ -428,7 +408,6 @@ add_fp_unittest(
   HDRS
     RoundToIntegerTest.h
   DEPENDS
-    libc.include.math
     libc.src.errno.errno
     libc.src.fenv.feclearexcept
     libc.src.fenv.feraiseexcept
@@ -447,7 +426,6 @@ add_fp_unittest(
   HDRS
     RIntTest.h
   DEPENDS
-    libc.include.math
     libc.src.math.rint
     libc.src.__support.FPUtil.fenv_impl
     libc.src.__support.FPUtil.fp_bits
@@ -463,7 +441,6 @@ add_fp_unittest(
   HDRS
     RIntTest.h
   DEPENDS
-    libc.include.math
     libc.src.math.rintf
     libc.src.__support.FPUtil.fenv_impl
     libc.src.__support.FPUtil.fp_bits
@@ -479,7 +456,6 @@ add_fp_unittest(
   HDRS
     RIntTest.h
   DEPENDS
-    libc.include.math
     libc.src.math.rintl
     libc.src.__support.FPUtil.fenv_impl
     libc.src.__support.FPUtil.fp_bits
@@ -495,7 +471,6 @@ add_fp_unittest(
   HDRS
     RoundToIntegerTest.h
   DEPENDS
-    libc.include.math
     libc.src.math.lrint
     libc.src.__support.FPUtil.fenv_impl
     libc.src.__support.FPUtil.fp_bits
@@ -511,7 +486,6 @@ add_fp_unittest(
   HDRS
     RoundToIntegerTest.h
   DEPENDS
-    libc.include.math
     libc.src.math.lrintf
     libc.src.__support.FPUtil.fenv_impl
     libc.src.__support.FPUtil.fp_bits
@@ -527,7 +501,6 @@ add_fp_unittest(
   HDRS
     RoundToIntegerTest.h
   DEPENDS
-    libc.include.math
     libc.src.math.lrintl
     libc.src.__support.FPUtil.fenv_impl
     libc.src.__support.FPUtil.fp_bits
@@ -543,7 +516,6 @@ add_fp_unittest(
   HDRS
     RoundToIntegerTest.h
   DEPENDS
-    libc.include.math
     libc.src.math.llrint
     libc.src.__support.FPUtil.fenv_impl
     libc.src.__support.FPUtil.fp_bits
@@ -559,7 +531,6 @@ add_fp_unittest(
   HDRS
     RoundToIntegerTest.h
   DEPENDS
-    libc.include.math
     libc.src.math.llrintf
     libc.src.__support.FPUtil.fenv_impl
     libc.src.__support.FPUtil.fp_bits
@@ -575,7 +546,6 @@ add_fp_unittest(
   HDRS
     RoundToIntegerTest.h
   DEPENDS
-    libc.include.math
     libc.src.math.llrintl
     libc.src.__support.FPUtil.fenv_impl
     libc.src.__support.FPUtil.fp_bits
@@ -590,7 +560,6 @@ add_fp_unittest(
     expf_test.cpp
   DEPENDS
     libc.src.errno.errno
-    libc.include.math
     libc.src.math.expf
     libc.src.__support.FPUtil.fp_bits
 )
@@ -618,7 +587,6 @@ add_fp_unittest(
     exp2f_test.cpp
   DEPENDS
     libc.src.errno.errno
-    libc.include.math
     libc.src.math.exp2f
     libc.src.__support.FPUtil.fp_bits
 )
@@ -646,7 +614,6 @@ add_fp_unittest(
     exp10f_test.cpp
   DEPENDS
     libc.src.errno.errno
-    libc.include.math
     libc.src.math.exp10f
     libc.src.__support.FPUtil.fp_bits
 )
@@ -674,7 +641,6 @@ add_fp_unittest(
   HDRS
     CopySignTest.h
   DEPENDS
-    libc.include.math
     libc.src.math.copysign...
[truncated]

@lntue lntue requested review from petrhosek and frobtech April 4, 2024 05:25
Copy link
Contributor

@SchrodingerZhu SchrodingerZhu left a comment

Choose a reason for hiding this comment

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

The patch overall looks good to me. Do we expose any macro to end users to indicate full build and overlay build?

@lntue
Copy link
Contributor Author

lntue commented Apr 4, 2024

The patch overall looks good to me. Do we expose any macro to end users to indicate full build and overlay build?

For cmake cli, -DLLVM_LIBC_FULL_BUILD=ON should do it. For user codes:

  • Once everything is routed through proxy headers, there won't be any include/* headers, and users will just include system headers.
  • For full build mode, since our include/* headers will now only be included in this mode, and they can assume that we are the only headers of the system, and don't need to do any of the #include_next dances.

For implementations in src folder, we can use #ifdef LIBC_FULL_BUILD to check whether we are in full build mode or overlay mode.

Copy link
Contributor

@SchrodingerZhu SchrodingerZhu left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@nickdesaulniers nickdesaulniers left a comment

Choose a reason for hiding this comment

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

Thanks! I think this gives me a clearer picture of what the usage of "proxy" headers might look like (#87017).

${ADD_PROXY_HEADER_UNPARSED_ARGUMENTS}
DEPENDS ${deps}
)
endfunction()
Copy link
Member

Choose a reason for hiding this comment

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

ah, nice, I should rebase #87017 onto this cmake change.

libc/include/llvm-libc-macros/math-macros.h Outdated Show resolved Hide resolved
@lntue lntue merged commit 5748ad8 into llvm:main Apr 5, 2024
4 checks passed
@lntue lntue deleted the math_macros branch April 5, 2024 23:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bazel "Peripheral" support tier build system: utils/bazel libc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants