Skip to content

[libc][NFC] Remove named_pair #73952

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 1 commit into from
Dec 1, 2023

Conversation

gchatelet
Copy link
Contributor

@gchatelet gchatelet commented Nov 30, 2023

named_pair does not provide enough value to deserve its own header.

@llvmbot llvmbot added the libc label Nov 30, 2023
@llvmbot
Copy link
Member

llvmbot commented Nov 30, 2023

@llvm/pr-subscribers-libc

Author: Guillaume Chatelet (gchatelet)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/73952.diff

5 Files Affected:

  • (modified) libc/src/__support/CMakeLists.txt (-8)
  • (modified) libc/src/__support/math_extras.h (+8-3)
  • (removed) libc/src/__support/named_pair.h (-18)
  • (modified) libc/src/__support/number_pair.h (+4-2)
  • (modified) utils/bazel/llvm-project-overlay/libc/BUILD.bazel (-7)
diff --git a/libc/src/__support/CMakeLists.txt b/libc/src/__support/CMakeLists.txt
index a76b22960f5a504..d41a9339b17a9df 100644
--- a/libc/src/__support/CMakeLists.txt
+++ b/libc/src/__support/CMakeLists.txt
@@ -10,12 +10,6 @@ add_header_library(
     libc.src.__support.CPP.new
 )
 
-add_header_library(
-  named_pair
-  HDRS
-    named_pair.h
-)
-
 add_header_library(
   common
   HDRS
@@ -40,7 +34,6 @@ add_header_library(
   HDRS
     math_extras.h
   DEPENDS
-    .named_pair
     libc.src.__support.CPP.type_traits
     libc.src.__support.macros.attributes
     libc.src.__support.macros.config
@@ -185,7 +178,6 @@ add_header_library(
   HDRS
     number_pair.h
   DEPENDS
-    .named_pair
     libc.src.__support.CPP.type_traits
 )
 
diff --git a/libc/src/__support/math_extras.h b/libc/src/__support/math_extras.h
index cc22aa49d02601b..860cdda8586d1ea 100644
--- a/libc/src/__support/math_extras.h
+++ b/libc/src/__support/math_extras.h
@@ -10,7 +10,6 @@
 #ifndef LLVM_LIBC_SRC___SUPPORT_MATH_EXTRAS_H
 #define LLVM_LIBC_SRC___SUPPORT_MATH_EXTRAS_H
 
-#include "named_pair.h"
 #include "src/__support/CPP/type_traits.h"
 #include "src/__support/macros/attributes.h" // LIBC_INLINE
 #include "src/__support/macros/config.h"     // LIBC_HAS_BUILTIN
@@ -18,7 +17,10 @@
 namespace LIBC_NAMESPACE {
 
 // Add with carry
-DEFINE_NAMED_PAIR_TEMPLATE(SumCarry, sum, carry);
+template <typename T> struct SumCarry {
+  T sum;
+  T carry;
+};
 
 // This version is always valid for constexpr.
 template <typename T>
@@ -91,7 +93,10 @@ add_with_carry<unsigned long long>(unsigned long long a, unsigned long long b,
 #endif // LIBC_HAS_BUILTIN(__builtin_addc)
 
 // Subtract with borrow
-DEFINE_NAMED_PAIR_TEMPLATE(DiffBorrow, diff, borrow);
+template <typename T> struct DiffBorrow {
+  T diff;
+  T borrow;
+};
 
 // This version is always valid for constexpr.
 template <typename T>
diff --git a/libc/src/__support/named_pair.h b/libc/src/__support/named_pair.h
deleted file mode 100644
index bd7dccf9810c7f7..000000000000000
--- a/libc/src/__support/named_pair.h
+++ /dev/null
@@ -1,18 +0,0 @@
-//===-- Utilities for pairs of numbers. -------------------------*- C++ -*-===//
-//
-// 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_SRC___SUPPORT_NAMED_PAIR_H
-#define LLVM_LIBC_SRC___SUPPORT_NAMED_PAIR_H
-
-#define DEFINE_NAMED_PAIR_TEMPLATE(Name, FirstField, SecondField)              \
-  template <typename T1, typename T2 = T1> struct Name {                       \
-    T1 FirstField;                                                             \
-    T2 SecondField;                                                            \
-  }
-
-#endif // LLVM_LIBC_SRC___SUPPORT_NAMED_PAIR_H
diff --git a/libc/src/__support/number_pair.h b/libc/src/__support/number_pair.h
index 5e553d817994b4b..12e730836af2c67 100644
--- a/libc/src/__support/number_pair.h
+++ b/libc/src/__support/number_pair.h
@@ -10,13 +10,15 @@
 #define LLVM_LIBC_SRC___SUPPORT_NUMBER_PAIR_H
 
 #include "CPP/type_traits.h"
-#include "named_pair.h"
 
 #include <stddef.h>
 
 namespace LIBC_NAMESPACE {
 
-DEFINE_NAMED_PAIR_TEMPLATE(NumberPair, lo, hi);
+template <typename T> struct NumberPair {
+  T lo;
+  T hi;
+};
 
 template <typename T>
 cpp::enable_if_t<cpp::is_integral_v<T> && cpp::is_unsigned_v<T>, NumberPair<T>>
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index a0a6a4366ea7537..2f9f5a4f90efc00 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -431,7 +431,6 @@ libc_support_library(
     hdrs = ["src/__support/number_pair.h"],
     deps = [
         ":__support_cpp_type_traits",
-        ":__support_named_pair",
     ],
 )
 
@@ -587,11 +586,6 @@ libc_support_library(
     ],
 )
 
-libc_support_library(
-    name = "__support_named_pair",
-    hdrs = ["src/__support/named_pair.h"],
-)
-
 libc_support_library(
     name = "__support_bit",
     hdrs = ["src/__support/bit.h"],
@@ -608,7 +602,6 @@ libc_support_library(
         ":__support_cpp_type_traits",
         ":__support_macros_attributes",
         ":__support_macros_config",
-        ":__support_named_pair",
     ],
 )
 

@gchatelet gchatelet requested a review from lntue November 30, 2023 15:21
@gchatelet gchatelet merged commit bb98227 into llvm:main Dec 1, 2023
@gchatelet gchatelet deleted the remove_low_utility_header branch December 1, 2023 09:30
asb added a commit to asb/llvm-project that referenced this pull request Dec 5, 2023
…ructions

Follows llvm#73952 doing the same thing for the nneg flag on zext.
asb added a commit that referenced this pull request Dec 6, 2023
…ructions (#74517)

Follows #73952 doing the same thing for the nneg flag on zext (i.e.,
exposing support in the C API).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants