[llvm] b46d035 - [NFC] Refactor byteswapped writes

Chris Bieneman via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 10 18:39:23 PDT 2023


Author: Chris Bieneman
Date: 2023-08-10T20:39:08-05:00
New Revision: b46d0353d4a8dee4ea5f905cc33412370195a6fc

URL: https://github.com/llvm/llvm-project/commit/b46d0353d4a8dee4ea5f905cc33412370195a6fc
DIFF: https://github.com/llvm/llvm-project/commit/b46d0353d4a8dee4ea5f905cc33412370195a6fc.diff

LOG: [NFC] Refactor byteswapped writes

This is an extremely small refactoring to writing byte-swapped values
in the PSV data. I've broken the PPC-BE bots a few times with changes
here because of the fragility of how byte-swapping was being done. This
should make it less likely for me to break BE builders in the future.

Reviewed By: bogner, bob80905

Differential Revision: https://reviews.llvm.org/D156814

Added: 
    

Modified: 
    llvm/lib/MC/DXContainerPSVInfo.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/MC/DXContainerPSVInfo.cpp b/llvm/lib/MC/DXContainerPSVInfo.cpp
index 77466219d0f152..efd75370bbf064 100644
--- a/llvm/lib/MC/DXContainerPSVInfo.cpp
+++ b/llvm/lib/MC/DXContainerPSVInfo.cpp
@@ -8,6 +8,7 @@
 
 #include "llvm/MC/DXContainerPSVInfo.h"
 #include "llvm/BinaryFormat/DXContainer.h"
+#include "llvm/Support/EndianStream.h"
 #include "llvm/Support/raw_ostream.h"
 
 using namespace llvm;
@@ -31,24 +32,16 @@ void PSVRuntimeInfo::write(raw_ostream &OS, uint32_t Version) const {
     InfoSize = sizeof(dxbc::PSV::v2::RuntimeInfo);
     BindingSize = sizeof(dxbc::PSV::v2::ResourceBindInfo);
   }
-  uint32_t InfoSizeSwapped = InfoSize;
-  if (sys::IsBigEndianHost)
-    sys::swapByteOrder(InfoSizeSwapped);
   // Write the size of the info.
-  OS.write(reinterpret_cast<const char *>(&InfoSizeSwapped), sizeof(uint32_t));
+
+  support::endian::write(OS, InfoSize, support::little);
   // Write the info itself.
   OS.write(reinterpret_cast<const char *>(&BaseData), InfoSize);
 
   uint32_t ResourceCount = static_cast<uint32_t>(Resources.size());
-  uint32_t BindingSizeSwapped = BindingSize;
-  if (sys::IsBigEndianHost) {
-    sys::swapByteOrder(ResourceCount);
-    sys::swapByteOrder(BindingSizeSwapped);
-  }
 
-  OS.write(reinterpret_cast<const char *>(&ResourceCount), sizeof(uint32_t));
-  OS.write(reinterpret_cast<const char *>(&BindingSizeSwapped),
-           sizeof(uint32_t));
+  support::endian::write(OS, ResourceCount, support::little);
+  support::endian::write(OS, BindingSize, support::little);
 
   for (const auto &Res : Resources)
     OS.write(reinterpret_cast<const char *>(&Res), BindingSize);


        


More information about the llvm-commits mailing list