Skip to content

Commit 5748ad8

Browse files
authored
[libc] Add proxy header math_macros.h. (#87598)
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`.
1 parent 3b33724 commit 5748ad8

File tree

147 files changed

+222
-417
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

147 files changed

+222
-417
lines changed

libc/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ endforeach()
381381

382382
add_subdirectory(include)
383383
add_subdirectory(config)
384+
add_subdirectory(hdr)
384385
add_subdirectory(src)
385386
add_subdirectory(utils)
386387

libc/fuzzing/math/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ add_libc_fuzzer(
88
SingleInputSingleOutputDiff.h
99
TwoInputSingleOutputDiff.h
1010
DEPENDS
11+
libc.hdr.math_macros
1112
libc.src.math.ceil
1213
libc.src.math.ceilf
1314
libc.src.math.ceill

libc/fuzzing/math/RemQuoDiff.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
#include "src/__support/FPUtil/FPBits.h"
1313

14-
#include "include/llvm-libc-macros/math-macros.h"
14+
#include "hdr/math_macros.h"
1515
#include <stddef.h>
1616
#include <stdint.h>
1717

libc/fuzzing/stdlib/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ add_libc_fuzzer(
2222
SRCS
2323
strtofloat_fuzz.cpp
2424
DEPENDS
25+
libc.hdr.math_macros
2526
libc.src.stdlib.atof
2627
libc.src.stdlib.strtof
2728
libc.src.stdlib.strtod

libc/fuzzing/stdlib/strtofloat_fuzz.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
#include "src/__support/FPUtil/FPBits.h"
1818

19-
#include "include/llvm-libc-macros/math-macros.h"
19+
#include "hdr/math_macros.h"
2020
#include <stddef.h>
2121
#include <stdint.h>
2222

libc/hdr/CMakeLists.txt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
function(add_proxy_header_library target_name)
2+
cmake_parse_arguments(
3+
"ADD_PROXY_HEADER"
4+
"" # Optional arguments
5+
"" # Single value arguments
6+
"DEPENDS;FULL_BUILD_DEPENDS" # Multi-value arguments
7+
${ARGN}
8+
)
9+
10+
set(deps "")
11+
if(ADD_PROXY_HEADER_DEPENDS)
12+
list(APPEND deps ${ADD_PROXY_HEADER_DEPENDS})
13+
endif()
14+
15+
if(LLVM_LIBC_FULL_BUILD AND ADD_PROXY_HEADER_FULL_BUILD_DEPENDS)
16+
list(APPEND deps ${ADD_PROXY_HEADER_FULL_BUILD_DEPENDS})
17+
endif()
18+
19+
add_header_library(
20+
${target_name}
21+
${ADD_PROXY_HEADER_UNPARSED_ARGUMENTS}
22+
DEPENDS ${deps}
23+
)
24+
endfunction()
25+
26+
add_proxy_header_library(
27+
math_macros
28+
HDRS
29+
math_macros.h
30+
FULL_BUILD_DEPENDS
31+
libc.include.llvm-libc-macros.math_macros
32+
libc.include.math
33+
)

libc/hdr/math_macros.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===-- Definition of macros from math.h ----------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_HDR_MATH_MACROS_H
10+
#define LLVM_LIBC_HDR_MATH_MACROS_H
11+
12+
#ifdef LIBC_FULL_BUILD
13+
14+
#include "include/llvm-libc-macros/math-macros.h"
15+
16+
#else // Overlay mode
17+
18+
#include <math.h>
19+
20+
#endif // LLVM_LIBC_FULL_BUILD
21+
22+
#endif // LLVM_LIBC_HDR_MATH_MACROS_H

libc/include/llvm-libc-macros/math-macros.h

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@
99
#ifndef LLVM_LIBC_MACROS_MATH_MACROS_H
1010
#define LLVM_LIBC_MACROS_MATH_MACROS_H
1111

12-
// TODO: Remove this. This is a temporary fix for a downstream problem.
13-
// This cannot be left permanently since it would require downstream users to
14-
// define this macro.
15-
#ifdef LIBC_FULL_BUILD
16-
1712
#include "limits-macros.h"
1813

1914
#define FP_NAN 0
@@ -62,6 +57,7 @@
6257
// the identifier, even in places with parentheses where a function-like macro
6358
// will be expanded (such as a function declaration in a C++ namespace).
6459

60+
// TODO: Move generic functional math macros to a separate header file.
6561
#ifdef __cplusplus
6662

6763
template <typename T> inline constexpr bool isfinite(T x) {
@@ -84,10 +80,4 @@ template <typename T> inline constexpr bool isnan(T x) {
8480

8581
#endif
8682

87-
#else // LIBC_FULL_BUILD
88-
89-
#include <math.h>
90-
91-
#endif // LIBC_FULL_BUILD
92-
9383
#endif // LLVM_LIBC_MACROS_MATH_MACROS_H

libc/src/__support/FPUtil/CMakeLists.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ add_header_library(
44
FEnvImpl.h
55
DEPENDS
66
libc.include.fenv
7-
libc.include.math
7+
libc.hdr.math_macros
88
libc.src.__support.macros.attributes
99
libc.src.errno.errno
1010
)
@@ -15,7 +15,6 @@ add_header_library(
1515
rounding_mode.h
1616
DEPENDS
1717
libc.include.fenv
18-
libc.include.math
1918
libc.src.__support.macros.attributes
2019
libc.src.__support.macros.properties.architectures
2120
libc.src.__support.macros.sanitizer
@@ -59,9 +58,9 @@ add_header_library(
5958
.fp_bits
6059
.fenv_impl
6160
.rounding_mode
61+
libc.hdr.math_macros
6262
libc.src.__support.CPP.type_traits
6363
libc.src.__support.common
64-
libc.include.math
6564
libc.src.errno.errno
6665
)
6766

@@ -216,12 +215,12 @@ add_header_library(
216215
.dyadic_float
217216
.nearest_integer_operations
218217
.normal_float
218+
libc.hdr.math_macros
219219
libc.src.__support.CPP.bit
220220
libc.src.__support.CPP.limits
221221
libc.src.__support.CPP.type_traits
222222
libc.src.__support.common
223223
libc.src.__support.macros.optimization
224-
libc.include.math
225224
libc.src.errno.errno
226225
)
227226

libc/src/__support/FPUtil/FEnvImpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#ifndef LLVM_LIBC_SRC___SUPPORT_FPUTIL_FENVIMPL_H
1010
#define LLVM_LIBC_SRC___SUPPORT_FPUTIL_FENVIMPL_H
1111

12-
#include "include/llvm-libc-macros/math-macros.h"
12+
#include "hdr/math_macros.h"
1313
#include "src/__support/macros/attributes.h" // LIBC_INLINE
1414
#include "src/__support/macros/properties/architectures.h"
1515
#include "src/errno/libc_errno.h"

libc/src/__support/FPUtil/ManipulationFunctions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include "dyadic_float.h"
1616
#include "rounding_mode.h"
1717

18-
#include "include/llvm-libc-macros/math-macros.h"
18+
#include "hdr/math_macros.h"
1919
#include "src/__support/CPP/bit.h"
2020
#include "src/__support/CPP/limits.h" // INT_MAX, INT_MIN
2121
#include "src/__support/CPP/type_traits.h"

libc/src/__support/FPUtil/NearestIntegerOperations.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include "FPBits.h"
1414
#include "rounding_mode.h"
1515

16-
#include "include/llvm-libc-macros/math-macros.h"
16+
#include "hdr/math_macros.h"
1717
#include "src/__support/CPP/type_traits.h"
1818
#include "src/__support/common.h"
1919

libc/src/math/generic/CMakeLists.txt

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ add_object_library(
102102
HDRS
103103
math_utils.h
104104
DEPENDS
105+
libc.hdr.math_macros
105106
libc.include.errno
106-
libc.include.math
107107
libc.src.errno.errno
108108
)
109109

@@ -139,7 +139,6 @@ add_entrypoint_object(
139139
../cosf.h
140140
DEPENDS
141141
.sincosf_utils
142-
libc.include.math
143142
libc.src.errno.errno
144143
libc.src.__support.FPUtil.basic_operations
145144
libc.src.__support.FPUtil.fenv_impl
@@ -162,7 +161,6 @@ add_entrypoint_object(
162161
DEPENDS
163162
.range_reduction
164163
.sincosf_utils
165-
libc.include.math
166164
libc.src.errno.errno
167165
libc.src.__support.FPUtil.basic_operations
168166
libc.src.__support.FPUtil.fenv_impl
@@ -185,7 +183,6 @@ add_entrypoint_object(
185183
DEPENDS
186184
.range_reduction
187185
.sincosf_utils
188-
libc.include.math
189186
libc.src.errno.errno
190187
libc.src.__support.FPUtil.fenv_impl
191188
libc.src.__support.FPUtil.fp_bits
@@ -207,7 +204,6 @@ add_entrypoint_object(
207204
DEPENDS
208205
.range_reduction
209206
.sincosf_utils
210-
libc.include.math
211207
libc.src.errno.errno
212208
libc.src.__support.FPUtil.fenv_impl
213209
libc.src.__support.FPUtil.fenv_impl
@@ -770,7 +766,6 @@ add_entrypoint_object(
770766
libc.src.__support.FPUtil.multiply_add
771767
libc.src.__support.FPUtil.polyeval
772768
libc.src.__support.macros.optimization
773-
libc.include.math
774769
COMPILE_OPTIONS
775770
-O3
776771
)
@@ -785,7 +780,6 @@ add_entrypoint_object(
785780
.common_constants
786781
.explogxf
787782
libc.include.errno
788-
libc.include.math
789783
libc.src.__support.CPP.bit
790784
libc.src.__support.CPP.optional
791785
libc.src.__support.FPUtil.dyadic_float
@@ -821,7 +815,6 @@ add_entrypoint_object(
821815
libc.src.__support.macros.optimization
822816
libc.include.errno
823817
libc.src.errno.errno
824-
libc.include.math
825818
COMPILE_OPTIONS
826819
-O3
827820
)
@@ -836,7 +829,6 @@ add_entrypoint_object(
836829
.common_constants
837830
.explogxf
838831
libc.include.errno
839-
libc.include.math
840832
libc.src.__support.CPP.bit
841833
libc.src.__support.CPP.optional
842834
libc.src.__support.FPUtil.dyadic_float
@@ -871,7 +863,6 @@ add_header_library(
871863
libc.src.__support.common
872864
libc.include.errno
873865
libc.src.errno.errno
874-
libc.include.math
875866
)
876867

877868
add_entrypoint_object(
@@ -917,7 +908,6 @@ add_entrypoint_object(
917908
.common_constants
918909
.explogxf
919910
libc.include.errno
920-
libc.include.math
921911
libc.src.__support.CPP.bit
922912
libc.src.__support.CPP.optional
923913
libc.src.__support.FPUtil.dyadic_float
@@ -951,7 +941,6 @@ add_header_library(
951941
libc.src.__support.common
952942
libc.include.errno
953943
libc.src.errno.errno
954-
libc.include.math
955944
COMPILE_OPTIONS
956945
-O3
957946
)
@@ -978,7 +967,6 @@ add_entrypoint_object(
978967
.common_constants
979968
.explogxf
980969
libc.include.errno
981-
libc.include.math
982970
libc.src.__support.CPP.bit
983971
libc.src.__support.CPP.optional
984972
libc.src.__support.FPUtil.dyadic_float
@@ -1014,7 +1002,6 @@ add_entrypoint_object(
10141002
libc.src.__support.macros.optimization
10151003
libc.include.errno
10161004
libc.src.errno.errno
1017-
libc.include.math
10181005
COMPILE_OPTIONS
10191006
-O3
10201007
)
@@ -1031,7 +1018,6 @@ add_entrypoint_object(
10311018
.exp2f_impl
10321019
.explogxf
10331020
libc.include.errno
1034-
libc.include.math
10351021
libc.src.__support.CPP.bit
10361022
libc.src.__support.CPP.optional
10371023
libc.src.__support.FPUtil.fenv_impl
@@ -2755,7 +2741,6 @@ add_object_library(
27552741
libc.src.__support.common
27562742
libc.include.errno
27572743
libc.src.errno.errno
2758-
libc.include.math
27592744
COMPILE_OPTIONS
27602745
-O3
27612746
)

libc/src/math/generic/math_utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#ifndef LLVM_LIBC_SRC_MATH_GENERIC_MATH_UTILS_H
1010
#define LLVM_LIBC_SRC_MATH_GENERIC_MATH_UTILS_H
1111

12-
#include "include/llvm-libc-macros/math-macros.h"
12+
#include "hdr/math_macros.h"
1313
#include "src/__support/CPP/bit.h"
1414
#include "src/__support/CPP/type_traits.h"
1515
#include "src/__support/common.h"

libc/test/CMakeLists.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ add_subdirectory(include)
1818
add_subdirectory(src)
1919
add_subdirectory(utils)
2020

21-
if(LLVM_LIBC_FULL_BUILD AND NOT LIBC_TARGET_OS_IS_BAREMETAL)
22-
add_subdirectory(IntegrationTest)
23-
endif()
24-
2521
if(NOT LLVM_LIBC_FULL_BUILD)
2622
return()
2723
endif()
@@ -31,4 +27,6 @@ if(NOT ${LIBC_TARGET_OS} STREQUAL "linux" AND
3127
# Integration tests are currently only available for linux and the GPU.
3228
return()
3329
endif()
30+
31+
add_subdirectory(IntegrationTest)
3432
add_subdirectory(integration)

libc/test/UnitTest/FPMatcher.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include "test/UnitTest/StringUtils.h"
1919
#include "test/UnitTest/Test.h"
2020

21-
#include "include/llvm-libc-macros/math-macros.h"
21+
#include "hdr/math_macros.h"
2222

2323
namespace LIBC_NAMESPACE {
2424
namespace testing {

libc/test/src/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ function(add_fp_unittest name)
33
"MATH_UNITTEST"
44
"NEED_MPFR;UNIT_TEST_ONLY;HERMETIC_TEST_ONLY" # Optional arguments
55
"" # Single value arguments
6-
"LINK_LIBRARIES" # Multi-value arguments
6+
"LINK_LIBRARIES;DEPENDS" # Multi-value arguments
77
${ARGN}
88
)
99

@@ -28,11 +28,17 @@ function(add_fp_unittest name)
2828
endif()
2929
list(APPEND MATH_UNITTEST_LINK_LIBRARIES LibcFPTestHelpers)
3030

31+
set(deps libc.hdr.math_macros)
32+
if(MATH_UNITTEST_DEPENDS)
33+
list(APPEND deps ${MATH_UNITTEST_DEPENDS})
34+
endif()
35+
3136
add_libc_test(
3237
${name}
3338
${test_type}
3439
LINK_LIBRARIES "${MATH_UNITTEST_LINK_LIBRARIES}"
3540
"${MATH_UNITTEST_UNPARSED_ARGUMENTS}"
41+
DEPENDS "${deps}"
3642
)
3743
endfunction(add_fp_unittest)
3844

0 commit comments

Comments
 (0)