[libc-commits] [libc] 71405d9 - [libc] Select FPUtils implementations via code instead of build

Guillaume Chatelet via libc-commits libc-commits at lists.llvm.org
Fri Dec 3 07:50:54 PST 2021


Author: Guillaume Chatelet
Date: 2021-12-03T15:48:41Z
New Revision: 71405d90f042792c243d6c134c5cc2bc23853980

URL: https://github.com/llvm/llvm-project/commit/71405d90f042792c243d6c134c5cc2bc23853980
DIFF: https://github.com/llvm/llvm-project/commit/71405d90f042792c243d6c134c5cc2bc23853980.diff

LOG: [libc] Select FPUtils implementations via code instead of build

We want to simplify the build system and rely on code to do the implementation selection.
This is in preparation of adding a Bazel configuration (D114712).

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

Added: 
    libc/src/__support/FPUtil/FEnvImpl.h
    libc/src/__support/FPUtil/x86_64/LongDoubleBits.h
    libc/src/__support/FPUtil/x86_64/NextAfterLongDouble.h
    libc/src/__support/FPUtil/x86_64/SqrtLongDouble.h

Modified: 
    libc/src/__support/FPUtil/CMakeLists.txt
    libc/src/__support/FPUtil/FMA.h
    libc/src/__support/FPUtil/FPBits.h
    libc/src/__support/FPUtil/ManipulationFunctions.h
    libc/src/__support/FPUtil/Sqrt.h
    libc/src/__support/FPUtil/aarch64/FEnvImpl.h
    libc/src/__support/FPUtil/aarch64/FMA.h
    libc/src/__support/FPUtil/x86_64/FEnvImpl.h
    libc/src/__support/FPUtil/x86_64/FMA.h

Removed: 
    libc/src/__support/FPUtil/DummyFEnvImpl.h
    libc/src/__support/FPUtil/LongDoubleBitsX86.h
    libc/src/__support/FPUtil/NextAfterLongDoubleX86.h
    libc/src/__support/FPUtil/SqrtLongDoubleX86.h


################################################################################
diff  --git a/libc/src/__support/FPUtil/CMakeLists.txt b/libc/src/__support/FPUtil/CMakeLists.txt
index 01703e017b1bf..6d005a9166c25 100644
--- a/libc/src/__support/FPUtil/CMakeLists.txt
+++ b/libc/src/__support/FPUtil/CMakeLists.txt
@@ -1,20 +1,7 @@
-if(${LIBC_TARGET_ARCHITECTURE_IS_X86})
-  set(LONG_DOUBLE_HDR LongDoubleBitsX86.h)
-else()
-  set(LONG_DOUBLE_HDR)
-endif()
-
-if(EXISTS ${LIBC_TARGET_ARCHITECTURE})
-  set(FENV_IMPL ${LIBC_TARGET_ARCHITECTURE}/FEnvImpl.h)
-else()
-  set(FENV_IMPL DummyFEnvImpl.h)
-endif()
-
 add_header_library(
   fputil
   HDRS
-    ${LONG_DOUBLE_HDR}
-    ${FENV_IMPL}
+    FEnvImpl.h
     BasicOperations.h
     DivisionAndRemainderOperations.h
     FEnvUtils.h

diff  --git a/libc/src/__support/FPUtil/DummyFEnvImpl.h b/libc/src/__support/FPUtil/FEnvImpl.h
similarity index 80%
rename from libc/src/__support/FPUtil/DummyFEnvImpl.h
rename to libc/src/__support/FPUtil/FEnvImpl.h
index cdc3df478f79d..967df4bcf1d22 100644
--- a/libc/src/__support/FPUtil/DummyFEnvImpl.h
+++ b/libc/src/__support/FPUtil/FEnvImpl.h
@@ -1,4 +1,4 @@
-//===-- Dummy floating point environment manipulation functins --*- C++ -*-===//
+//===-- Floating point environment manipulation functions -------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -9,6 +9,13 @@
 #ifndef LLVM_LIBC_SRC_SUPPORT_FPUTIL_DUMMY_FENVIMPL_H
 #define LLVM_LIBC_SRC_SUPPORT_FPUTIL_DUMMY_FENVIMPL_H
 
+#include "src/__support/architectures.h"
+
+#if defined(LLVM_LIBC_ARCH_AARCH64)
+#include "aarch64/FEnvImpl.h"
+#elif defined(LLVM_LIBC_ARCH_X86)
+#include "x86_64/FEnvImpl.h"
+#else
 #include <fenv.h>
 #include <math.h>
 
@@ -35,5 +42,6 @@ static inline int setEnv(const fenv_t *) { return 0; }
 
 } // namespace fputil
 } // namespace __llvm_libc
+#endif
 
 #endif // LLVM_LIBC_SRC_SUPPORT_FPUTIL_DUMMY_FENVIMPL_H

diff  --git a/libc/src/__support/FPUtil/FMA.h b/libc/src/__support/FPUtil/FMA.h
index 5f35bec644ebb..c735c069fd4da 100644
--- a/libc/src/__support/FPUtil/FMA.h
+++ b/libc/src/__support/FPUtil/FMA.h
@@ -9,7 +9,6 @@
 #ifndef LLVM_LIBC_SRC_SUPPORT_FPUTIL_FMA_H
 #define LLVM_LIBC_SRC_SUPPORT_FPUTIL_FMA_H
 
-#include "src/__support/CPP/TypeTraits.h"
 #include "src/__support/architectures.h"
 
 #if defined(LLVM_LIBC_ARCH_X86_64)
@@ -18,6 +17,7 @@
 #include "aarch64/FMA.h"
 #else
 #include "generic/FMA.h"
+#include "src/__support/CPP/TypeTraits.h"
 
 namespace __llvm_libc {
 namespace fputil {

diff  --git a/libc/src/__support/FPUtil/FPBits.h b/libc/src/__support/FPUtil/FPBits.h
index b761dd7f98285..10a3dcd07681e 100644
--- a/libc/src/__support/FPUtil/FPBits.h
+++ b/libc/src/__support/FPUtil/FPBits.h
@@ -153,7 +153,7 @@ template <typename T> union FPBits {
 } // namespace __llvm_libc
 
 #ifdef SPECIAL_X86_LONG_DOUBLE
-#include "src/__support/FPUtil/LongDoubleBitsX86.h"
+#include "x86_64/LongDoubleBits.h"
 #endif
 
 #endif // LLVM_LIBC_SRC_SUPPORT_FPUTIL_FP_BITS_H

diff  --git a/libc/src/__support/FPUtil/ManipulationFunctions.h b/libc/src/__support/FPUtil/ManipulationFunctions.h
index 053eae311fbaf..3c7783ea73a4e 100644
--- a/libc/src/__support/FPUtil/ManipulationFunctions.h
+++ b/libc/src/__support/FPUtil/ManipulationFunctions.h
@@ -179,7 +179,7 @@ static inline T nextafter(T from, T to) {
 } // namespace __llvm_libc
 
 #ifdef SPECIAL_X86_LONG_DOUBLE
-#include "NextAfterLongDoubleX86.h"
+#include "x86_64/NextAfterLongDouble.h"
 #endif // SPECIAL_X86_LONG_DOUBLE
 
 #endif // LLVM_LIBC_SRC_SUPPORT_FPUTIL_MANIPULATION_FUNCTIONS_H

diff  --git a/libc/src/__support/FPUtil/Sqrt.h b/libc/src/__support/FPUtil/Sqrt.h
index b6c7cc4f7e785..093f1b3b6e4a9 100644
--- a/libc/src/__support/FPUtil/Sqrt.h
+++ b/libc/src/__support/FPUtil/Sqrt.h
@@ -186,7 +186,7 @@ static inline T sqrt(T x) {
 } // namespace __llvm_libc
 
 #ifdef SPECIAL_X86_LONG_DOUBLE
-#include "SqrtLongDoubleX86.h"
+#include "x86_64/SqrtLongDouble.h"
 #endif // SPECIAL_X86_LONG_DOUBLE
 
 #endif // LLVM_LIBC_SRC_SUPPORT_FPUTIL_SQRT_H

diff  --git a/libc/src/__support/FPUtil/aarch64/FEnvImpl.h b/libc/src/__support/FPUtil/aarch64/FEnvImpl.h
index d59e8f097a922..129319373ea88 100644
--- a/libc/src/__support/FPUtil/aarch64/FEnvImpl.h
+++ b/libc/src/__support/FPUtil/aarch64/FEnvImpl.h
@@ -9,6 +9,12 @@
 #ifndef LLVM_LIBC_SRC_SUPPORT_FPUTIL_AARCH64_FENVIMPL_H
 #define LLVM_LIBC_SRC_SUPPORT_FPUTIL_AARCH64_FENVIMPL_H
 
+#include "src/__support/architectures.h"
+
+#if !defined(LLVM_LIBC_ARCH_AARCH64)
+#error "Invalid include"
+#endif
+
 #include <arm_acle.h>
 #include <fenv.h>
 #include <stdint.h>

diff  --git a/libc/src/__support/FPUtil/aarch64/FMA.h b/libc/src/__support/FPUtil/aarch64/FMA.h
index bb9214468c245..c236c9a90b741 100644
--- a/libc/src/__support/FPUtil/aarch64/FMA.h
+++ b/libc/src/__support/FPUtil/aarch64/FMA.h
@@ -9,6 +9,12 @@
 #ifndef LLVM_LIBC_SRC_SUPPORT_FPUTIL_AARCH64_FMA_H
 #define LLVM_LIBC_SRC_SUPPORT_FPUTIL_AARCH64_FMA_H
 
+#include "src/__support/architectures.h"
+
+#if !defined(LLVM_LIBC_ARCH_AARCH64)
+#error "Invalid include"
+#endif
+
 #include "src/__support/CPP/TypeTraits.h"
 
 namespace __llvm_libc {

diff  --git a/libc/src/__support/FPUtil/x86_64/FEnvImpl.h b/libc/src/__support/FPUtil/x86_64/FEnvImpl.h
index 0a220a268c9c1..8e2336c011544 100644
--- a/libc/src/__support/FPUtil/x86_64/FEnvImpl.h
+++ b/libc/src/__support/FPUtil/x86_64/FEnvImpl.h
@@ -9,6 +9,12 @@
 #ifndef LLVM_LIBC_SRC_SUPPORT_FPUTIL_X86_64_FENVIMPL_H
 #define LLVM_LIBC_SRC_SUPPORT_FPUTIL_X86_64_FENVIMPL_H
 
+#include "src/__support/architectures.h"
+
+#if !defined(LLVM_LIBC_ARCH_X86)
+#error "Invalid include"
+#endif
+
 #include <fenv.h>
 #include <stdint.h>
 

diff  --git a/libc/src/__support/FPUtil/x86_64/FMA.h b/libc/src/__support/FPUtil/x86_64/FMA.h
index 59f55a2c5d192..ca8bfb41a8ee2 100644
--- a/libc/src/__support/FPUtil/x86_64/FMA.h
+++ b/libc/src/__support/FPUtil/x86_64/FMA.h
@@ -9,6 +9,12 @@
 #ifndef LLVM_LIBC_SRC_SUPPORT_FPUTIL_X86_64_FMA_H
 #define LLVM_LIBC_SRC_SUPPORT_FPUTIL_X86_64_FMA_H
 
+#include "src/__support/architectures.h"
+
+#if !defined(LLVM_LIBC_ARCH_X86)
+#error "Invalid include"
+#endif
+
 #include "src/__support/CPP/TypeTraits.h"
 
 namespace __llvm_libc {

diff  --git a/libc/src/__support/FPUtil/LongDoubleBitsX86.h b/libc/src/__support/FPUtil/x86_64/LongDoubleBits.h
similarity index 93%
rename from libc/src/__support/FPUtil/LongDoubleBitsX86.h
rename to libc/src/__support/FPUtil/x86_64/LongDoubleBits.h
index 77611ad281c66..43a3d415e81ef 100644
--- a/libc/src/__support/FPUtil/LongDoubleBitsX86.h
+++ b/libc/src/__support/FPUtil/x86_64/LongDoubleBits.h
@@ -6,10 +6,16 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_LIBC_SRC_SUPPORT_FPUTIL_LONG_DOUBLE_BITS_X86_H
-#define LLVM_LIBC_SRC_SUPPORT_FPUTIL_LONG_DOUBLE_BITS_X86_H
+#ifndef LLVM_LIBC_SRC_SUPPORT_FPUTIL_X86_64_LONG_DOUBLE_BITS_H
+#define LLVM_LIBC_SRC_SUPPORT_FPUTIL_X86_64_LONG_DOUBLE_BITS_H
 
-#include "FPBits.h"
+#include "src/__support/architectures.h"
+
+#if !defined(LLVM_LIBC_ARCH_X86)
+#error "Invalid include"
+#endif
+
+#include "src/__support/FPUtil/FPBits.h"
 
 #include <stdint.h>
 
@@ -181,4 +187,4 @@ static_assert(
 } // namespace fputil
 } // namespace __llvm_libc
 
-#endif // LLVM_LIBC_SRC_SUPPORT_FPUTIL_LONG_DOUBLE_BITS_X86_H
+#endif // LLVM_LIBC_SRC_SUPPORT_FPUTIL_X86_64_LONG_DOUBLE_BITS_H

diff  --git a/libc/src/__support/FPUtil/NextAfterLongDoubleX86.h b/libc/src/__support/FPUtil/x86_64/NextAfterLongDouble.h
similarity index 91%
rename from libc/src/__support/FPUtil/NextAfterLongDoubleX86.h
rename to libc/src/__support/FPUtil/x86_64/NextAfterLongDouble.h
index f3bf96b525148..a6e9461be9516 100644
--- a/libc/src/__support/FPUtil/NextAfterLongDoubleX86.h
+++ b/libc/src/__support/FPUtil/x86_64/NextAfterLongDouble.h
@@ -6,10 +6,16 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_LIBC_SRC_SUPPORT_FPUTIL_NEXT_AFTER_LONG_DOUBLE_X86_H
-#define LLVM_LIBC_SRC_SUPPORT_FPUTIL_NEXT_AFTER_LONG_DOUBLE_X86_H
+#ifndef LLVM_LIBC_SRC_SUPPORT_FPUTIL_X86_64_NEXT_AFTER_LONG_DOUBLE_H
+#define LLVM_LIBC_SRC_SUPPORT_FPUTIL_X86_64_NEXT_AFTER_LONG_DOUBLE_H
 
-#include "FPBits.h"
+#include "src/__support/architectures.h"
+
+#if !defined(LLVM_LIBC_ARCH_X86)
+#error "Invalid include"
+#endif
+
+#include "src/__support/FPUtil/FPBits.h"
 
 #include <stdint.h>
 
@@ -111,4 +117,4 @@ static inline long double nextafter(long double from, long double to) {
 } // namespace fputil
 } // namespace __llvm_libc
 
-#endif // LLVM_LIBC_SRC_SUPPORT_FPUTIL_NEXT_AFTER_LONG_DOUBLE_X86_H
+#endif // LLVM_LIBC_SRC_SUPPORT_FPUTIL_X86_64_NEXT_AFTER_LONG_DOUBLE_H

diff  --git a/libc/src/__support/FPUtil/SqrtLongDoubleX86.h b/libc/src/__support/FPUtil/x86_64/SqrtLongDouble.h
similarity index 93%
rename from libc/src/__support/FPUtil/SqrtLongDoubleX86.h
rename to libc/src/__support/FPUtil/x86_64/SqrtLongDouble.h
index 98875ba4f2333..e07af32345de4 100644
--- a/libc/src/__support/FPUtil/SqrtLongDoubleX86.h
+++ b/libc/src/__support/FPUtil/x86_64/SqrtLongDouble.h
@@ -6,8 +6,14 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_LIBC_SRC_SUPPORT_FPUTIL_SQRT_LONG_DOUBLE_X86_H
-#define LLVM_LIBC_SRC_SUPPORT_FPUTIL_SQRT_LONG_DOUBLE_X86_H
+#ifndef LLVM_LIBC_SRC_SUPPORT_FPUTIL_X86_64_SQRT_LONG_DOUBLE_H
+#define LLVM_LIBC_SRC_SUPPORT_FPUTIL_X86_64_SQRT_LONG_DOUBLE_H
+
+#include "src/__support/architectures.h"
+
+#if !defined(LLVM_LIBC_ARCH_X86)
+#error "Invalid include"
+#endif
 
 #include "FPBits.h"
 #include "Sqrt.h"
@@ -139,4 +145,4 @@ template <> inline long double sqrt<long double, 0>(long double x) {
 } // namespace fputil
 } // namespace __llvm_libc
 
-#endif // LLVM_LIBC_SRC_SUPPORT_FPUTIL_SQRT_LONG_DOUBLE_X86_H
+#endif // LLVM_LIBC_SRC_SUPPORT_FPUTIL_X86_64_SQRT_LONG_DOUBLE_H


        


More information about the libc-commits mailing list