This is an archive of the discontinued LLVM Phabricator instance.

Add support for reading and writing values with runtime-endianness
ClosedPublic

Authored by zturner on Feb 2 2017, 11:14 AM.

Details

Summary

llvm/Support/Endian.h contains a bunch of functions and classes for working with values whose endianness is known at compile time. But it does not contain anything for working with values where the endianness is only known at runtime.

This patch adds overloads of read and write that take the endianness not as a template parameter, but as a function argument. The versions of the function that use the template parameter are updated to call the version that takes the runtime argument. Since all these functions are inlined, the demotion from a compile-time value to a runtime value should not incur any additional overhead.

The long term motivation for this is to convert LLDB's endian-aware code to use LLVM instead of reinventing all of their own code for doing byte swaps, theyir own enumeration for representing byte order, etc. For now, this just adds the necessary machinery.

Since the template functions now call the runtime functions, no additional tests are necessary, as there are already tests written against the templated versions of the functions.

Diff Detail

Event Timeline

zturner created this revision.Feb 2 2017, 11:14 AM
Bigcheese accepted this revision.Feb 2 2017, 3:40 PM

This seems fine. Can you first verify that -O2 with gcc, clang, and msvc still get it right? I expect them to, just want to make sure.

This revision is now accepted and ready to land.Feb 2 2017, 3:40 PM

Code looks fine on MSVC and Clang. I don't have the ability to test on GCC, but given that both MSVC and Clang get it right, I would be rather surprised if GCC does not. Seem reasonable?

This revision was automatically updated to reflect the committed changes.