[llvm] [Support] Remove redundant forwarding functions read/write (NFC) (PR #66051)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 12 00:32:37 PDT 2023


https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/66051:

We don't need these forwarding functions if we add a default template
parameter to their callees.


>From 7097149cc1ec251ecf12c8d571cd25edc9dbe71b Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Tue, 12 Sep 2023 00:10:07 -0700
Subject: [PATCH] [Support] Remove redundant forwarding functions read/write
 (NFC)

We don't need these forwarding functions if we add a default template
parameter to their callees.
---
 llvm/include/llvm/Support/Endian.h | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)

diff --git a/llvm/include/llvm/Support/Endian.h b/llvm/include/llvm/Support/Endian.h
index 5e7c1e961b9d1e0..bd6ce54f80c7bfa 100644
--- a/llvm/include/llvm/Support/Endian.h
+++ b/llvm/include/llvm/Support/Endian.h
@@ -59,7 +59,7 @@ inline value_type byte_swap(value_type value) {
 }
 
 /// Read a value of a particular endianness from memory.
-template <typename value_type, std::size_t alignment>
+template <typename value_type, std::size_t alignment = unaligned>
 inline value_type read(const void *memory, endianness endian) {
   value_type ret;
 
@@ -93,7 +93,7 @@ inline value_type readNext(const CharT *&memory) {
 }
 
 /// Write a value to memory with a particular endianness.
-template <typename value_type, std::size_t alignment>
+template <typename value_type, std::size_t alignment = unaligned>
 inline void write(void *memory, value_type value, endianness endian) {
   value = byte_swap<value_type>(value, endian);
   memcpy(LLVM_ASSUME_ALIGNED(
@@ -349,10 +349,6 @@ using aligned_big_t = detail::packed_endian_specific_integral<T, big, aligned>;
 
 namespace endian {
 
-template <typename T> inline T read(const void *P, endianness E) {
-  return read<T, unaligned>(P, E);
-}
-
 template <typename T, endianness E> inline T read(const void *P) {
   return *(const detail::packed_endian_specific_integral<T, E, unaligned> *)P;
 }
@@ -384,10 +380,6 @@ inline uint16_t read16be(const void *P) { return read16<big>(P); }
 inline uint32_t read32be(const void *P) { return read32<big>(P); }
 inline uint64_t read64be(const void *P) { return read64<big>(P); }
 
-template <typename T> inline void write(void *P, T V, endianness E) {
-  write<T, unaligned>(P, V, E);
-}
-
 template <typename T, endianness E> inline void write(void *P, T V) {
   *(detail::packed_endian_specific_integral<T, E, unaligned> *)P = V;
 }



More information about the llvm-commits mailing list