-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
[Support] Make readNext default to unaligned #88808
[Support] Make readNext default to unaligned #88808
Conversation
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.
@llvm/pr-subscribers-llvm-support Author: Kazu Hirata (kazutakahirata) ChangesWithout this patch, you would typically use readNext as: readNext<uint32_t, llvm::endianness::little, unaligned>(Ptr) which is quite mouthful. Since most serialization/deserialization readNext<uint32_t, llvm::endianness::little>(Ptr) I'm including a few examples of migration in this patch. I'll do the Note that writeNext already has the same trick for the alignment Full diff: https://github.com/llvm/llvm-project/pull/88808.diff 2 Files Affected:
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.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I just wanted to do the same as I am dabbling with ld.lld --debug-names
This is like how to we define There should be no codegen difference to aarch64/x86/ppc64, but certain 32-bit architectures and riscv64 -mstrict-align will have some penalty. |
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.