[lld] f6b8f05 - Use llvm::byteswap instead of ByteSwap_{16, 32, 64} (NFC)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Sat Jan 28 15:22:47 PST 2023
Author: Kazu Hirata
Date: 2023-01-28T15:22:37-08:00
New Revision: f6b8f05bb399e8f5fd176b2c9dd383cd029467f1
URL: https://github.com/llvm/llvm-project/commit/f6b8f05bb399e8f5fd176b2c9dd383cd029467f1
DIFF: https://github.com/llvm/llvm-project/commit/f6b8f05bb399e8f5fd176b2c9dd383cd029467f1.diff
LOG: Use llvm::byteswap instead of ByteSwap_{16,32,64} (NFC)
Added:
Modified:
clang/lib/Lex/HeaderMap.cpp
lld/COFF/DebugTypes.cpp
lldb/include/lldb/Core/Opcode.h
lldb/source/Core/Opcode.cpp
lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
lldb/source/Plugins/Instruction/ARM/EmulationStateARM.cpp
lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp
lldb/source/Symbol/ArmUnwindInfo.cpp
lldb/source/Utility/DataExtractor.cpp
llvm/lib/ExecutionEngine/JITLink/MachO.cpp
llvm/lib/Support/APInt.cpp
llvm/lib/Support/ConvertUTFWrapper.cpp
Removed:
################################################################################
diff --git a/clang/lib/Lex/HeaderMap.cpp b/clang/lib/Lex/HeaderMap.cpp
index bb50a4eef65c1..da0b8898f6900 100644
--- a/clang/lib/Lex/HeaderMap.cpp
+++ b/clang/lib/Lex/HeaderMap.cpp
@@ -77,8 +77,8 @@ bool HeaderMapImpl::checkHeader(const llvm::MemoryBuffer &File,
if (Header->Magic == HMAP_HeaderMagicNumber &&
Header->Version == HMAP_HeaderVersion)
NeedsByteSwap = false;
- else if (Header->Magic == llvm::ByteSwap_32(HMAP_HeaderMagicNumber) &&
- Header->Version == llvm::ByteSwap_16(HMAP_HeaderVersion))
+ else if (Header->Magic == llvm::byteswap<uint32_t>(HMAP_HeaderMagicNumber) &&
+ Header->Version == llvm::byteswap<uint16_t>(HMAP_HeaderVersion))
NeedsByteSwap = true; // Mixed endianness headermap.
else
return false; // Not a header map.
@@ -113,7 +113,7 @@ StringRef HeaderMapImpl::getFileName() const {
unsigned HeaderMapImpl::getEndianAdjustedWord(unsigned X) const {
if (!NeedsBSwap) return X;
- return llvm::ByteSwap_32(X);
+ return llvm::byteswap<uint32_t>(X);
}
/// getHeader - Return a reference to the file header, in unbyte-swapped form.
diff --git a/lld/COFF/DebugTypes.cpp b/lld/COFF/DebugTypes.cpp
index 7bbce84b2d548..95d4e53bb7707 100644
--- a/lld/COFF/DebugTypes.cpp
+++ b/lld/COFF/DebugTypes.cpp
@@ -1021,7 +1021,8 @@ uint32_t GHashTable::insert(COFFLinkerContext &ctx, GloballyHashedType ghash,
// type records are. Swap the byte order for better entropy. A better ghash
// won't need this.
uint32_t startIdx =
- ByteSwap_64(*reinterpret_cast<uint64_t *>(&ghash)) % tableSize;
+ llvm::byteswap<uint64_t>(*reinterpret_cast<uint64_t *>(&ghash)) %
+ tableSize;
// Do a linear probe starting at startIdx.
uint32_t idx = startIdx;
diff --git a/lldb/include/lldb/Core/Opcode.h b/lldb/include/lldb/Core/Opcode.h
index 70f2dbdf639f4..f72f2687b54fe 100644
--- a/lldb/include/lldb/Core/Opcode.h
+++ b/lldb/include/lldb/Core/Opcode.h
@@ -99,7 +99,8 @@ class Opcode {
case Opcode::eType8:
return m_data.inst8;
case Opcode::eType16:
- return GetEndianSwap() ? llvm::ByteSwap_16(m_data.inst16) : m_data.inst16;
+ return GetEndianSwap() ? llvm::byteswap<uint16_t>(m_data.inst16)
+ : m_data.inst16;
case Opcode::eType16_2:
break;
case Opcode::eType32:
@@ -119,10 +120,12 @@ class Opcode {
case Opcode::eType8:
return m_data.inst8;
case Opcode::eType16:
- return GetEndianSwap() ? llvm::ByteSwap_16(m_data.inst16) : m_data.inst16;
+ return GetEndianSwap() ? llvm::byteswap<uint16_t>(m_data.inst16)
+ : m_data.inst16;
case Opcode::eType16_2: // passthrough
case Opcode::eType32:
- return GetEndianSwap() ? llvm::ByteSwap_32(m_data.inst32) : m_data.inst32;
+ return GetEndianSwap() ? llvm::byteswap<uint32_t>(m_data.inst32)
+ : m_data.inst32;
case Opcode::eType64:
break;
case Opcode::eTypeBytes:
@@ -138,12 +141,15 @@ class Opcode {
case Opcode::eType8:
return m_data.inst8;
case Opcode::eType16:
- return GetEndianSwap() ? llvm::ByteSwap_16(m_data.inst16) : m_data.inst16;
+ return GetEndianSwap() ? llvm::byteswap<uint16_t>(m_data.inst16)
+ : m_data.inst16;
case Opcode::eType16_2: // passthrough
case Opcode::eType32:
- return GetEndianSwap() ? llvm::ByteSwap_32(m_data.inst32) : m_data.inst32;
+ return GetEndianSwap() ? llvm::byteswap<uint32_t>(m_data.inst32)
+ : m_data.inst32;
case Opcode::eType64:
- return GetEndianSwap() ? llvm::ByteSwap_64(m_data.inst64) : m_data.inst64;
+ return GetEndianSwap() ? llvm::byteswap<uint64_t>(m_data.inst64)
+ : m_data.inst64;
case Opcode::eTypeBytes:
break;
}
diff --git a/lldb/source/Core/Opcode.cpp b/lldb/source/Core/Opcode.cpp
index a3fc97f95266d..3e30d98975d8a 100644
--- a/lldb/source/Core/Opcode.cpp
+++ b/lldb/source/Core/Opcode.cpp
@@ -103,7 +103,7 @@ uint32_t Opcode::GetData(DataExtractor &data) const {
buf = GetOpcodeDataBytes();
break;
case Opcode::eType16:
- *(uint16_t *)swap_buf = llvm::ByteSwap_16(m_data.inst16);
+ *(uint16_t *)swap_buf = llvm::byteswap<uint16_t>(m_data.inst16);
buf = swap_buf;
break;
case Opcode::eType16_2:
@@ -114,11 +114,11 @@ uint32_t Opcode::GetData(DataExtractor &data) const {
buf = swap_buf;
break;
case Opcode::eType32:
- *(uint32_t *)swap_buf = llvm::ByteSwap_32(m_data.inst32);
+ *(uint32_t *)swap_buf = llvm::byteswap<uint32_t>(m_data.inst32);
buf = swap_buf;
break;
case Opcode::eType64:
- *(uint32_t *)swap_buf = llvm::ByteSwap_64(m_data.inst64);
+ *(uint32_t *)swap_buf = llvm::byteswap<uint64_t>(m_data.inst64);
buf = swap_buf;
break;
case Opcode::eTypeBytes:
diff --git a/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp b/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
index 09dd94d9186d3..fcbaf7e1ed7d2 100644
--- a/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
+++ b/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
@@ -413,13 +413,13 @@ DynamicLoaderDarwinKernel::ReadMachHeader(addr_t addr, Process *process, llvm::M
if (header.magic == llvm::MachO::MH_CIGAM ||
header.magic == llvm::MachO::MH_CIGAM_64) {
- header.magic = llvm::ByteSwap_32(header.magic);
- header.cputype = llvm::ByteSwap_32(header.cputype);
- header.cpusubtype = llvm::ByteSwap_32(header.cpusubtype);
- header.filetype = llvm::ByteSwap_32(header.filetype);
- header.ncmds = llvm::ByteSwap_32(header.ncmds);
- header.sizeofcmds = llvm::ByteSwap_32(header.sizeofcmds);
- header.flags = llvm::ByteSwap_32(header.flags);
+ header.magic = llvm::byteswap<uint32_t>(header.magic);
+ header.cputype = llvm::byteswap<uint32_t>(header.cputype);
+ header.cpusubtype = llvm::byteswap<uint32_t>(header.cpusubtype);
+ header.filetype = llvm::byteswap<uint32_t>(header.filetype);
+ header.ncmds = llvm::byteswap<uint32_t>(header.ncmds);
+ header.sizeofcmds = llvm::byteswap<uint32_t>(header.sizeofcmds);
+ header.flags = llvm::byteswap<uint32_t>(header.flags);
}
return true;
diff --git a/lldb/source/Plugins/Instruction/ARM/EmulationStateARM.cpp b/lldb/source/Plugins/Instruction/ARM/EmulationStateARM.cpp
index 1bb96fc8a2f7f..ca118375b8abc 100644
--- a/lldb/source/Plugins/Instruction/ARM/EmulationStateARM.cpp
+++ b/lldb/source/Plugins/Instruction/ARM/EmulationStateARM.cpp
@@ -118,7 +118,7 @@ size_t EmulationStateARM::ReadPseudoMemory(
return 0;
if (endian::InlHostByteOrder() == lldb::eByteOrderBig)
- value = llvm::ByteSwap_32(value);
+ value = llvm::byteswap<uint32_t>(value);
*((uint32_t *)dst) = value;
} else if (length == 8) {
uint32_t value1 = pseudo_state->ReadFromPseudoAddress(addr, success);
@@ -130,8 +130,8 @@ size_t EmulationStateARM::ReadPseudoMemory(
return 0;
if (endian::InlHostByteOrder() == lldb::eByteOrderBig) {
- value1 = llvm::ByteSwap_32(value1);
- value2 = llvm::ByteSwap_32(value2);
+ value1 = llvm::byteswap<uint32_t>(value1);
+ value2 = llvm::byteswap<uint32_t>(value2);
}
((uint32_t *)dst)[0] = value1;
((uint32_t *)dst)[1] = value2;
@@ -157,7 +157,7 @@ size_t EmulationStateARM::WritePseudoMemory(
uint32_t value;
memcpy (&value, dst, sizeof (uint32_t));
if (endian::InlHostByteOrder() == lldb::eByteOrderBig)
- value = llvm::ByteSwap_32(value);
+ value = llvm::byteswap<uint32_t>(value);
pseudo_state->StoreToPseudoAddress(addr, value);
return length;
@@ -168,8 +168,8 @@ size_t EmulationStateARM::WritePseudoMemory(
memcpy(&value2, static_cast<const uint8_t *>(dst) + sizeof(uint32_t),
sizeof(uint32_t));
if (endian::InlHostByteOrder() == lldb::eByteOrderBig) {
- value1 = llvm::ByteSwap_32(value1);
- value2 = llvm::ByteSwap_32(value2);
+ value1 = llvm::byteswap<uint32_t>(value1);
+ value2 = llvm::byteswap<uint32_t>(value2);
}
pseudo_state->StoreToPseudoAddress(addr, value1);
diff --git a/lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp b/lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp
index 11e9b0e369f09..9bae7b0df5281 100644
--- a/lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp
+++ b/lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp
@@ -136,13 +136,13 @@ bool ProcessMachCore::CheckAddressForDyldOrKernel(lldb::addr_t addr,
return false;
if (header.magic == llvm::MachO::MH_CIGAM ||
header.magic == llvm::MachO::MH_CIGAM_64) {
- header.magic = llvm::ByteSwap_32(header.magic);
- header.cputype = llvm::ByteSwap_32(header.cputype);
- header.cpusubtype = llvm::ByteSwap_32(header.cpusubtype);
- header.filetype = llvm::ByteSwap_32(header.filetype);
- header.ncmds = llvm::ByteSwap_32(header.ncmds);
- header.sizeofcmds = llvm::ByteSwap_32(header.sizeofcmds);
- header.flags = llvm::ByteSwap_32(header.flags);
+ header.magic = llvm::byteswap<uint32_t>(header.magic);
+ header.cputype = llvm::byteswap<uint32_t>(header.cputype);
+ header.cpusubtype = llvm::byteswap<uint32_t>(header.cpusubtype);
+ header.filetype = llvm::byteswap<uint32_t>(header.filetype);
+ header.ncmds = llvm::byteswap<uint32_t>(header.ncmds);
+ header.sizeofcmds = llvm::byteswap<uint32_t>(header.sizeofcmds);
+ header.flags = llvm::byteswap<uint32_t>(header.flags);
}
if (header.magic == llvm::MachO::MH_MAGIC ||
diff --git a/lldb/source/Symbol/ArmUnwindInfo.cpp b/lldb/source/Symbol/ArmUnwindInfo.cpp
index 60935a33827ff..6bc3bd6cc5edf 100644
--- a/lldb/source/Symbol/ArmUnwindInfo.cpp
+++ b/lldb/source/Symbol/ArmUnwindInfo.cpp
@@ -78,7 +78,7 @@ uint8_t ArmUnwindInfo::GetByteAtOffset(const uint32_t *data,
uint16_t offset) const {
uint32_t value = data[offset / 4];
if (m_byte_order != endian::InlHostByteOrder())
- value = llvm::ByteSwap_32(value);
+ value = llvm::byteswap<uint32_t>(value);
return (value >> ((3 - (offset % 4)) * 8)) & 0xff;
}
diff --git a/lldb/source/Utility/DataExtractor.cpp b/lldb/source/Utility/DataExtractor.cpp
index a0cd945b7445c..fc8160ff3053c 100644
--- a/lldb/source/Utility/DataExtractor.cpp
+++ b/lldb/source/Utility/DataExtractor.cpp
@@ -70,39 +70,39 @@ static inline uint16_t ReadSwapInt16(const unsigned char *ptr,
offset_t offset) {
uint16_t value;
memcpy(&value, ptr + offset, 2);
- return llvm::ByteSwap_16(value);
+ return llvm::byteswap<uint16_t>(value);
}
static inline uint32_t ReadSwapInt32(const unsigned char *ptr,
offset_t offset) {
uint32_t value;
memcpy(&value, ptr + offset, 4);
- return llvm::ByteSwap_32(value);
+ return llvm::byteswap<uint32_t>(value);
}
static inline uint64_t ReadSwapInt64(const unsigned char *ptr,
offset_t offset) {
uint64_t value;
memcpy(&value, ptr + offset, 8);
- return llvm::ByteSwap_64(value);
+ return llvm::byteswap<uint64_t>(value);
}
static inline uint16_t ReadSwapInt16(const void *ptr) {
uint16_t value;
memcpy(&value, ptr, 2);
- return llvm::ByteSwap_16(value);
+ return llvm::byteswap<uint16_t>(value);
}
static inline uint32_t ReadSwapInt32(const void *ptr) {
uint32_t value;
memcpy(&value, ptr, 4);
- return llvm::ByteSwap_32(value);
+ return llvm::byteswap<uint32_t>(value);
}
static inline uint64_t ReadSwapInt64(const void *ptr) {
uint64_t value;
memcpy(&value, ptr, 8);
- return llvm::ByteSwap_64(value);
+ return llvm::byteswap<uint64_t>(value);
}
static inline uint64_t ReadMaxInt64(const uint8_t *data, size_t byte_size,
diff --git a/llvm/lib/ExecutionEngine/JITLink/MachO.cpp b/llvm/lib/ExecutionEngine/JITLink/MachO.cpp
index e49480c78662f..40086ccf2b66f 100644
--- a/llvm/lib/ExecutionEngine/JITLink/MachO.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/MachO.cpp
@@ -54,7 +54,7 @@ createLinkGraphFromMachOObject(MemoryBufferRef ObjectBuffer) {
uint32_t CPUType;
memcpy(&CPUType, Data.data() + 4, sizeof(uint32_t));
if (Magic == MachO::MH_CIGAM_64)
- CPUType = ByteSwap_32(CPUType);
+ CPUType = llvm::byteswap<uint32_t>(CPUType);
LLVM_DEBUG({
dbgs() << "jitLink_MachO: cputype = " << format("0x%08" PRIx32, CPUType)
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp
index dda7747be3f09..9e0d9064b6435 100644
--- a/llvm/lib/Support/APInt.cpp
+++ b/llvm/lib/Support/APInt.cpp
@@ -707,18 +707,18 @@ bool APInt::isSubsetOfSlowCase(const APInt &RHS) const {
APInt APInt::byteSwap() const {
assert(BitWidth >= 16 && BitWidth % 8 == 0 && "Cannot byteswap!");
if (BitWidth == 16)
- return APInt(BitWidth, ByteSwap_16(uint16_t(U.VAL)));
+ return APInt(BitWidth, llvm::byteswap<uint16_t>(U.VAL));
if (BitWidth == 32)
- return APInt(BitWidth, ByteSwap_32(unsigned(U.VAL)));
+ return APInt(BitWidth, llvm::byteswap<uint32_t>(U.VAL));
if (BitWidth <= 64) {
- uint64_t Tmp1 = ByteSwap_64(U.VAL);
+ uint64_t Tmp1 = llvm::byteswap<uint64_t>(U.VAL);
Tmp1 >>= (64 - BitWidth);
return APInt(BitWidth, Tmp1);
}
APInt Result(getNumWords() * APINT_BITS_PER_WORD, 0);
for (unsigned I = 0, N = getNumWords(); I != N; ++I)
- Result.U.pVal[I] = ByteSwap_64(U.pVal[N - I - 1]);
+ Result.U.pVal[I] = llvm::byteswap<uint64_t>(U.pVal[N - I - 1]);
if (Result.BitWidth != BitWidth) {
Result.lshrInPlace(Result.BitWidth - BitWidth);
Result.BitWidth = BitWidth;
diff --git a/llvm/lib/Support/ConvertUTFWrapper.cpp b/llvm/lib/Support/ConvertUTFWrapper.cpp
index 9bf3f8f8b897c..3fa7365e72d34 100644
--- a/llvm/lib/Support/ConvertUTFWrapper.cpp
+++ b/llvm/lib/Support/ConvertUTFWrapper.cpp
@@ -102,7 +102,7 @@ bool convertUTF16ToUTF8String(ArrayRef<char> SrcBytes, std::string &Out) {
if (Src[0] == UNI_UTF16_BYTE_ORDER_MARK_SWAPPED) {
ByteSwapped.insert(ByteSwapped.end(), Src, SrcEnd);
for (UTF16 &I : ByteSwapped)
- I = llvm::ByteSwap_16(I);
+ I = llvm::byteswap<uint16_t>(I);
Src = &ByteSwapped[0];
SrcEnd = &ByteSwapped[ByteSwapped.size() - 1] + 1;
}
@@ -160,7 +160,7 @@ bool convertUTF32ToUTF8String(ArrayRef<char> SrcBytes, std::string &Out) {
if (Src[0] == UNI_UTF32_BYTE_ORDER_MARK_SWAPPED) {
ByteSwapped.insert(ByteSwapped.end(), Src, SrcEnd);
for (UTF32 &I : ByteSwapped)
- I = llvm::ByteSwap_32(I);
+ I = llvm::byteswap<uint32_t>(I);
Src = &ByteSwapped[0];
SrcEnd = &ByteSwapped[ByteSwapped.size() - 1] + 1;
}
More information about the llvm-commits
mailing list