diff options
| author | Ulrich Weigand <ulrich.weigand@de.ibm.com> | 2023-06-23 09:17:53 +0200 |
|---|---|---|
| committer | Ulrich Weigand <ulrich.weigand@de.ibm.com> | 2023-06-23 09:22:55 +0200 |
| commit | bb0bbed610d86ba155f9c066c23038f7f34e2dbb (patch) | |
| tree | 76ace19cf3abeab8a0da72e9b4d6f81d599d59a5 /mlir/lib/Bytecode/Writer/BytecodeWriter.cpp | |
| parent | 7298bcf7f06145e2d4dfdb177b94dc42fc95dc55 (diff) | |
Fix bytecode reader/writer on big-endian platforms
This makes the bytecode reader/writer work on big-endian platforms.
The only problem was related to encoding of multi-byte integers,
where both reader and writer code make implicit assumptions about
endianness of the host platform.
This fixes the current test failures on s390x, and in addition allows
to remove the UNSUPPORTED markers from all other bytecode-related
test cases - they now also all pass on s390x.
Also adding a GFAIL_SKIP to the MultiModuleWithResource unit test,
as this still fails due to an unrelated endian bug regarding
decoding of external resources.
Differential Revision: https://reviews.llvm.org/D153567
Reviewed By: mehdi_amini, jpienaar, rriddle
Diffstat (limited to 'mlir/lib/Bytecode/Writer/BytecodeWriter.cpp')
| -rw-r--r-- | mlir/lib/Bytecode/Writer/BytecodeWriter.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/mlir/lib/Bytecode/Writer/BytecodeWriter.cpp b/mlir/lib/Bytecode/Writer/BytecodeWriter.cpp index 03c7a53a34e5..936117aa2b8f 100644 --- a/mlir/lib/Bytecode/Writer/BytecodeWriter.cpp +++ b/mlir/lib/Bytecode/Writer/BytecodeWriter.cpp @@ -21,6 +21,7 @@ #include "llvm/ADT/SmallString.h" #include "llvm/ADT/SmallVector.h" #include "llvm/Support/raw_ostream.h" +#include "llvm/Support/Endian.h" #include <cstddef> #include <cstdint> #include <cstring> @@ -538,7 +539,8 @@ void EncodingEmitter::emitMultiByteVarInt(uint64_t value) { if (LLVM_LIKELY(it >>= 7) == 0) { uint64_t encodedValue = (value << 1) | 0x1; encodedValue <<= (numBytes - 1); - emitBytes({reinterpret_cast<uint8_t *>(&encodedValue), numBytes}); + llvm::support::ulittle64_t encodedValueLE(encodedValue); + emitBytes({reinterpret_cast<uint8_t *>(&encodedValueLE), numBytes}); return; } } @@ -546,7 +548,8 @@ void EncodingEmitter::emitMultiByteVarInt(uint64_t value) { // If the value is too large to encode in a single byte, emit a special all // zero marker byte and splat the value directly. emitByte(0); - emitBytes({reinterpret_cast<uint8_t *>(&value), sizeof(value)}); + llvm::support::ulittle64_t valueLE(value); + emitBytes({reinterpret_cast<uint8_t *>(&valueLE), sizeof(valueLE)}); } //===----------------------------------------------------------------------===// |
