[libc] Enable MPFR library for math functions test

Included more math functions to Windows's entrypoints
and made a cmake option (-DLLVM_LIBC_MPFR_INSTALL_PATH)
where the user can specify the install path where the MPFR
library was built so it can be linked. The try_compile was
moved to LLVMLibCCheckMPFR.cmake, so the variable that is
set after this process can retain its value in other files
of the same parent file. A direct reason for this is for
LIBC_TESTS_CAN_USE_MPFR to be true when the user specifies
MPFR's path and retain its value even after leaving the file.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D106894

GitOrigin-RevId: 8baa87d91811a3da0dc69550b84a773d98902c8b
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 37d996f..bfab38e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -19,6 +19,7 @@
 
 # Defines LIBC_TARGET_ARCHITECTURE and associated macros.
 include(LLVMLibCArchitectures)
+include(LLVMLibCCheckMPFR)
 
 # Flags to pass down to the compiler while building the libc functions.
 set(LIBC_COMPILE_OPTIONS_DEFAULT "" CACHE STRING "Architecture to tell clang to optimize for (e.g. -march=... or -mcpu=...)")
diff --git a/cmake/modules/LLVMLibCCheckMPFR.cmake b/cmake/modules/LLVMLibCCheckMPFR.cmake
new file mode 100644
index 0000000..46f679f
--- /dev/null
+++ b/cmake/modules/LLVMLibCCheckMPFR.cmake
@@ -0,0 +1,14 @@
+set(LLVM_LIBC_MPFR_INSTALL_PATH "" CACHE PATH "Path to where MPFR is installed (e.g. C:/src/install or ~/src/install)")
+
+if(LLVM_LIBC_MPFR_INSTALL_PATH)
+  set(LIBC_TESTS_CAN_USE_MPFR TRUE)
+else()
+  try_compile(
+    LIBC_TESTS_CAN_USE_MPFR
+    ${CMAKE_CURRENT_BINARY_DIR}
+    SOURCES
+    ${LIBC_SOURCE_DIR}/utils/MPFRWrapper/check_mpfr.cpp
+    LINK_LIBRARIES
+      -lmpfr -lgmp
+  )
+endif()
diff --git a/config/windows/README.md b/config/windows/README.md
index 8e01a40..ca3cf1a 100644
--- a/config/windows/README.md
+++ b/config/windows/README.md
@@ -62,6 +62,24 @@
     cmake -G Ninja ../llvm-project/llvm -DCMAKE_C_COMPILER=C:/src/clang-build/bin/clang-cl.exe -DCMAKE_CXX_COMPILER=C:/src/clang-build/bin/clang-cl.exe  -DLLVM_TARGETS_TO_BUILD=X86 -DLLVM_FORCE_BUILD_RUNTIME=libc -DLLVM_ENABLE_PROJECTS=libc -DLLVM_NATIVE_ARCH=x86_64 -DLLVM_HOST_TRIPLE=x86_64-window-x86-gnu
     ```
 
+    Some LLVM libc math unittests test correctness/accuracy against results from
+    the [GNU MPFR library](https://www.mpfr.org/). If you want to run math tests
+    which use MPFR, and if MPFR on your machine is not installed in the default
+    include and linker lookup directories, then you can specify the MPFR install
+    directory by passing an additional CMake option as follows:
+
+    -DLLVM_LIBC_MPFR_INSTALL_PATH=<path/mpfr/install/dir>
+
+    If the above option is specified, then `${LLVM_LIBC_MPFR_INSTALL_PATH}/include`
+    will be added to the include directories, and
+    `${LLVM_LIBC_MPFR_INSTALL_PATH}/lib` will be added to the linker lookup
+    directories.
+
+    NOTE: The GNU MPFR library depends on the
+    [GNU GMP library](https://gmplib.org/). If you specify the above option, then it
+    will be assumed that GMP is also installed in the same directory or availabe in
+    the default paths.
+
 10. Build LLVM libc using:
 
     ```
diff --git a/config/windows/entrypoints.txt b/config/windows/entrypoints.txt
index 9ef14fe..20a59a0 100644
--- a/config/windows/entrypoints.txt
+++ b/config/windows/entrypoints.txt
@@ -45,30 +45,73 @@
     libc.src.math.copysign
     libc.src.math.copysignf
     libc.src.math.copysignl
-    libc.src.math.fdimf
+    libc.src.math.ceil
+    libc.src.math.ceilf
+    libc.src.math.ceill
+    libc.src.math.fabs
+    libc.src.math.fabsf
+    libc.src.math.fabsl
     libc.src.math.fdim
+    libc.src.math.fdimf
     libc.src.math.fdiml
+    libc.src.math.floor
+    libc.src.math.floorf
+    libc.src.math.floorl
+    libc.src.math.fma
+    libc.src.math.fmaf
     libc.src.math.fmin
     libc.src.math.fminf
     libc.src.math.fminl
     libc.src.math.fmax
     libc.src.math.fmaxf
     libc.src.math.fmaxl
+    libc.src.math.frexp
+    libc.src.math.frexpf
+    libc.src.math.frexpl
+    libc.src.math.hypot
+    libc.src.math.hypotf
     libc.src.math.ilogb
     libc.src.math.ilogbf
     libc.src.math.ilogbl
     libc.src.math.ldexp
     libc.src.math.ldexpf
     libc.src.math.ldexpl
+    libc.src.math.llround
+    libc.src.math.llroundf
+    libc.src.math.llroundl
     libc.src.math.logb
     libc.src.math.logbf
-    libc.src.math.logbl
+    libc.src.math.logbl 
+    libc.src.math.lround
+    libc.src.math.lroundf
+    libc.src.math.lroundl
     libc.src.math.modf
     libc.src.math.modff
     libc.src.math.modfl
+    libc.src.math.nearbyint
+    libc.src.math.nearbyintf
+    libc.src.math.nearbyintl
     libc.src.math.nextafter
     libc.src.math.nextafterf
     libc.src.math.nextafterl
+    libc.src.math.remainderf
+    libc.src.math.remainder
+    libc.src.math.remainderl
+    libc.src.math.remquof
+    libc.src.math.remquo
+    libc.src.math.remquol
+    libc.src.math.rint
+    libc.src.math.rintf
+    libc.src.math.rintl
+    libc.src.math.round
+    libc.src.math.roundf
+    libc.src.math.roundl
+    libc.src.math.sqrt
+    libc.src.math.sqrtf
+    libc.src.math.sqrtl
+    libc.src.math.trunc
+    libc.src.math.truncf
+    libc.src.math.truncl 
 )
 
 set(TARGET_LLVMLIBC_ENTRYPOINTS
diff --git a/utils/MPFRWrapper/CMakeLists.txt b/utils/MPFRWrapper/CMakeLists.txt
index 6f1bb76..6084653 100644
--- a/utils/MPFRWrapper/CMakeLists.txt
+++ b/utils/MPFRWrapper/CMakeLists.txt
@@ -1,19 +1,14 @@
-try_compile(
-  LIBC_TESTS_CAN_USE_MPFR
-  ${CMAKE_CURRENT_BINARY_DIR}
-  SOURCES
-    ${CMAKE_CURRENT_SOURCE_DIR}/check_mpfr.cpp
-  LINK_LIBRARIES
-    -lmpfr -lgmp
-)
-
 if(LIBC_TESTS_CAN_USE_MPFR)
   add_library(libcMPFRWrapper
     MPFRUtils.cpp
     MPFRUtils.h
   )
   add_dependencies(libcMPFRWrapper libc.utils.CPP.standalone_cpp libc.utils.FPUtil.fputil LibcUnitTest)
-  target_link_libraries(libcMPFRWrapper -lmpfr -lgmp LibcFPTestHelpers LibcUnitTest)
+  if(EXISTS ${LLVM_LIBC_MPFR_INSTALL_PATH})
+    target_include_directories(libcMPFRWrapper PUBLIC ${LLVM_LIBC_MPFR_INSTALL_PATH}/include)
+    target_link_directories(libcMPFRWrapper PUBLIC ${LLVM_LIBC_MPFR_INSTALL_PATH}/lib)
+  endif()
+  target_link_libraries(libcMPFRWrapper LibcFPTestHelpers LibcUnitTest mpfr gmp)
 else()
   message(WARNING "Math tests using MPFR will be skipped.")
 endif()