[llvm] 568368a - [Support] Make readNext default to unaligned (#88808)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 15 19:05:35 PDT 2024
Author: Kazu Hirata
Date: 2024-04-15T19:05:30-07:00
New Revision: 568368a43e5b4adb3c5d105a0eff3e0c13c0af8c
URL: https://github.com/llvm/llvm-project/commit/568368a43e5b4adb3c5d105a0eff3e0c13c0af8c
DIFF: https://github.com/llvm/llvm-project/commit/568368a43e5b4adb3c5d105a0eff3e0c13c0af8c.diff
LOG: [Support] Make readNext default to unaligned (#88808)
Without this patch, you would typically use readNext as:
readNext<uint32_t, llvm::endianness::little, unaligned>(Ptr)
which is quite mouthful. Since most serialization/deserialization
operations are unaligned accesses, this patch makes the alignment
template parameter default to unaligned, allowing us to say:
readNext<uint32_t, llvm::endianness::little>(Ptr)
I'm including a few examples of migration in this patch. I'll do the
rest in a separate patch.
Note that writeNext already has the same trick for the alignment
template parameter.
Added:
Modified:
llvm/include/llvm/Support/Endian.h
llvm/include/llvm/Support/OnDiskHashTable.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/Support/Endian.h b/llvm/include/llvm/Support/Endian.h
index 1cdb5ca0d5eaa1..30e0852b972c5a 100644
--- a/llvm/include/llvm/Support/Endian.h
+++ b/llvm/include/llvm/Support/Endian.h
@@ -80,8 +80,8 @@ template <typename value_type, std::size_t alignment, typename CharT>
return ret;
}
-template <typename value_type, endianness endian, std::size_t alignment,
- typename CharT>
+template <typename value_type, endianness endian,
+ std::size_t alignment = unaligned, typename CharT>
[[nodiscard]] inline value_type readNext(const CharT *&memory) {
return readNext<value_type, alignment, CharT>(memory, endian);
}
diff --git a/llvm/include/llvm/Support/OnDiskHashTable.h b/llvm/include/llvm/Support/OnDiskHashTable.h
index 0a8cbbd8b18832..f6b4055e74de7e 100644
--- a/llvm/include/llvm/Support/OnDiskHashTable.h
+++ b/llvm/include/llvm/Support/OnDiskHashTable.h
@@ -368,14 +368,12 @@ template <typename Info> class OnDiskChainedHashTable {
// 'Items' starts with a 16-bit unsigned integer representing the
// number of items in this bucket.
- unsigned Len =
- endian::readNext<uint16_t, llvm::endianness::little, unaligned>(Items);
+ unsigned Len = endian::readNext<uint16_t, llvm::endianness::little>(Items);
for (unsigned i = 0; i < Len; ++i) {
// Read the hash.
hash_value_type ItemHash =
- endian::readNext<hash_value_type, llvm::endianness::little,
- unaligned>(Items);
+ endian::readNext<hash_value_type, llvm::endianness::little>(Items);
// Determine the length of the key and the data.
const std::pair<offset_type, offset_type> &L =
@@ -473,8 +471,7 @@ class OnDiskIterableChainedHashTable : public OnDiskChainedHashTable<Info> {
// 'Items' starts with a 16-bit unsigned integer representing the
// number of items in this bucket.
NumItemsInBucketLeft =
- endian::readNext<uint16_t, llvm::endianness::little, unaligned>(
- Ptr);
+ endian::readNext<uint16_t, llvm::endianness::little>(Ptr);
}
Ptr += sizeof(hash_value_type); // Skip the hash.
// Determine the length of the key and the data.
More information about the llvm-commits
mailing list