Skip to content

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

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

Merged
merged 7 commits into from
Apr 5, 2024
Merged
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
1 change: 1 addition & 0 deletions libc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ endforeach()

add_subdirectory(include)
add_subdirectory(config)
add_subdirectory(hdr)
add_subdirectory(src)
add_subdirectory(utils)

Expand Down
1 change: 1 addition & 0 deletions libc/fuzzing/math/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion libc/fuzzing/math/RemQuoDiff.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
1 change: 1 addition & 0 deletions libc/fuzzing/stdlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion libc/fuzzing/stdlib/strtofloat_fuzz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
33 changes: 33 additions & 0 deletions libc/hdr/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
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.


add_proxy_header_library(
math_macros
HDRS
math_macros.h
FULL_BUILD_DEPENDS
libc.include.llvm-libc-macros.math_macros
libc.include.math
)
22 changes: 22 additions & 0 deletions libc/hdr/math_macros.h
Original file line number Diff line number Diff line change
@@ -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 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
12 changes: 1 addition & 11 deletions libc/include/llvm-libc-macros/math-macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@
#ifndef LLVM_LIBC_MACROS_MATH_MACROS_H
#define LLVM_LIBC_MACROS_MATH_MACROS_H

// TODO: Remove this. This is a temporary fix for a downstream problem.
// This cannot be left permanently since it would require downstream users to
// define this macro.
#ifdef LIBC_FULL_BUILD

#include "limits-macros.h"

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

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

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

#endif

#else // LIBC_FULL_BUILD

#include <math.h>

#endif // LIBC_FULL_BUILD

#endif // LLVM_LIBC_MACROS_MATH_MACROS_H
7 changes: 3 additions & 4 deletions libc/src/__support/FPUtil/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -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
Expand Down Expand Up @@ -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
)

Expand Down Expand Up @@ -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
)

Expand Down
2 changes: 1 addition & 1 deletion libc/src/__support/FPUtil/FEnvImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion libc/src/__support/FPUtil/ManipulationFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion libc/src/__support/FPUtil/NearestIntegerOperations.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
17 changes: 1 addition & 16 deletions libc/src/math/generic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -770,7 +766,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
)
Expand All @@ -785,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
Expand Down Expand Up @@ -821,7 +815,6 @@ add_entrypoint_object(
libc.src.__support.macros.optimization
libc.include.errno
libc.src.errno.errno
libc.include.math
COMPILE_OPTIONS
-O3
)
Expand All @@ -836,7 +829,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
Expand Down Expand Up @@ -871,7 +863,6 @@ add_header_library(
libc.src.__support.common
libc.include.errno
libc.src.errno.errno
libc.include.math
)

add_entrypoint_object(
Expand Down Expand Up @@ -917,7 +908,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
Expand Down Expand Up @@ -951,7 +941,6 @@ add_header_library(
libc.src.__support.common
libc.include.errno
libc.src.errno.errno
libc.include.math
COMPILE_OPTIONS
-O3
)
Expand All @@ -978,7 +967,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
Expand Down Expand Up @@ -1014,7 +1002,6 @@ add_entrypoint_object(
libc.src.__support.macros.optimization
libc.include.errno
libc.src.errno.errno
libc.include.math
COMPILE_OPTIONS
-O3
)
Expand All @@ -1031,7 +1018,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
Expand Down Expand Up @@ -2755,7 +2741,6 @@ add_object_library(
libc.src.__support.common
libc.include.errno
libc.src.errno.errno
libc.include.math
COMPILE_OPTIONS
-O3
)
Expand Down
2 changes: 1 addition & 1 deletion libc/src/math/generic/math_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 2 additions & 4 deletions libc/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
2 changes: 1 addition & 1 deletion libc/test/UnitTest/FPMatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 7 additions & 1 deletion libc/test/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
)

Expand All @@ -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)

Expand Down
Loading
Loading