Index: mlir/lib/Bytecode/Reader/BytecodeReader.cpp =================================================================== --- mlir/lib/Bytecode/Reader/BytecodeReader.cpp +++ mlir/lib/Bytecode/Reader/BytecodeReader.cpp @@ -27,6 +27,7 @@ #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringRef.h" +#include "llvm/Support/Endian.h" #include "llvm/Support/MemoryBufferRef.h" #include "llvm/Support/SaveAndRestore.h" #include "llvm/Support/SourceMgr.h" @@ -203,8 +204,14 @@ // Handle the overwhelming uncommon case where the value required all 8 // bytes (i.e. a really really big number). In this case, the marker byte is // all zeros: `00000000`. - if (LLVM_UNLIKELY(result == 0)) - return parseBytes(sizeof(result), reinterpret_cast(&result)); + if (LLVM_UNLIKELY(result == 0)) { + llvm::support::ulittle64_t resultLE; + if (failed(parseBytes(sizeof(resultLE), + reinterpret_cast(&resultLE)))) + return failure(); + result = resultLE; + return success(); + } return parseMultiByteVarInt(result); } @@ -305,12 +312,13 @@ "unexpected number of trailing zeros in varint encoding"); // Parse in the remaining bytes of the value. - if (failed(parseBytes(numBytes, reinterpret_cast(&result) + 1))) + llvm::support::ulittle64_t resultLE(result); + if (failed(parseBytes(numBytes, reinterpret_cast(&resultLE) + 1))) return failure(); // Shift out the low-order bits that were used to mark how the value was // encoded. - result >>= (numBytes + 1); + result = resultLE >> (numBytes + 1); return success(); } Index: mlir/lib/Bytecode/Writer/BytecodeWriter.cpp =================================================================== --- mlir/lib/Bytecode/Writer/BytecodeWriter.cpp +++ 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 #include #include @@ -538,7 +539,8 @@ if (LLVM_LIKELY(it >>= 7) == 0) { uint64_t encodedValue = (value << 1) | 0x1; encodedValue <<= (numBytes - 1); - emitBytes({reinterpret_cast(&encodedValue), numBytes}); + llvm::support::ulittle64_t encodedValueLE(encodedValue); + emitBytes({reinterpret_cast(&encodedValueLE), numBytes}); return; } } @@ -546,7 +548,8 @@ // 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(&value), sizeof(value)}); + llvm::support::ulittle64_t valueLE(value); + emitBytes({reinterpret_cast(&valueLE), sizeof(valueLE)}); } //===----------------------------------------------------------------------===// Index: mlir/test/Bytecode/general.mlir =================================================================== --- mlir/test/Bytecode/general.mlir +++ mlir/test/Bytecode/general.mlir @@ -1,8 +1,5 @@ // RUN: mlir-opt -allow-unregistered-dialect -emit-bytecode %s | mlir-opt -allow-unregistered-dialect | FileCheck %s -// Bytecode currently does not support big-endian platforms -// UNSUPPORTED: target=s390x-{{.*}} - // CHECK-LABEL: "bytecode.test1" // CHECK-NEXT: "unregistered.op"() {test_attr = #test.dynamic_singleton} : () -> () // CHECK-NEXT: "bytecode.empty"() : () -> () Index: mlir/test/Bytecode/invalid/invalid-dialect_section.mlir =================================================================== --- mlir/test/Bytecode/invalid/invalid-dialect_section.mlir +++ mlir/test/Bytecode/invalid/invalid-dialect_section.mlir @@ -1,9 +1,6 @@ // This file contains various failure test cases related to the structure of // the dialect section. -// Bytecode currently does not support big-endian platforms -// UNSUPPORTED: target=s390x-{{.*}} - //===--------------------------------------------------------------------===// // Dialect Name //===--------------------------------------------------------------------===// Index: mlir/test/Bytecode/invalid/invalid-ir_section.mlir =================================================================== --- mlir/test/Bytecode/invalid/invalid-ir_section.mlir +++ mlir/test/Bytecode/invalid/invalid-ir_section.mlir @@ -1,9 +1,6 @@ // This file contains various failure test cases related to the structure of // the IR section. -// Bytecode currently does not support big-endian platforms -// UNSUPPORTED: target=s390x-{{.*}} - //===--------------------------------------------------------------------===// // Operations //===--------------------------------------------------------------------===// Index: mlir/test/Bytecode/invalid/invalid-string_section.mlir =================================================================== --- mlir/test/Bytecode/invalid/invalid-string_section.mlir +++ mlir/test/Bytecode/invalid/invalid-string_section.mlir @@ -1,9 +1,6 @@ // This file contains various failure test cases related to the structure of // the string section. -// Bytecode currently does not support big-endian platforms -// UNSUPPORTED: target=s390x-{{.*}} - //===--------------------------------------------------------------------===// // Count //===--------------------------------------------------------------------===// Index: mlir/test/Bytecode/invalid/invalid-structure.mlir =================================================================== --- mlir/test/Bytecode/invalid/invalid-structure.mlir +++ mlir/test/Bytecode/invalid/invalid-structure.mlir @@ -1,9 +1,6 @@ // This file contains various failure test cases related to the structure of // a bytecode file. -// Bytecode currently does not support big-endian platforms -// UNSUPPORTED: target=s390x-{{.*}} - //===--------------------------------------------------------------------===// // Version //===--------------------------------------------------------------------===// Index: mlir/test/Bytecode/invalid/invalid_attr_type_offset_section.mlir =================================================================== --- mlir/test/Bytecode/invalid/invalid_attr_type_offset_section.mlir +++ mlir/test/Bytecode/invalid/invalid_attr_type_offset_section.mlir @@ -1,9 +1,6 @@ // This file contains various failure test cases related to the structure of // the attribute/type offset section. -// Bytecode currently does not support big-endian platforms -// UNSUPPORTED: target=s390x-{{.*}} - //===--------------------------------------------------------------------===// // Offset //===--------------------------------------------------------------------===// Index: mlir/test/Bytecode/invalid/invalid_attr_type_section.mlir =================================================================== --- mlir/test/Bytecode/invalid/invalid_attr_type_section.mlir +++ mlir/test/Bytecode/invalid/invalid_attr_type_section.mlir @@ -1,9 +1,6 @@ // This file contains various failure test cases related to the structure of // the attribute/type offset section. -// Bytecode currently does not support big-endian platforms -// UNSUPPORTED: target=s390x-{{.*}} - //===--------------------------------------------------------------------===// // Index //===--------------------------------------------------------------------===// Index: mlir/test/Bytecode/resources.mlir =================================================================== --- mlir/test/Bytecode/resources.mlir +++ mlir/test/Bytecode/resources.mlir @@ -1,8 +1,5 @@ // RUN: mlir-opt -emit-bytecode %s | mlir-opt | FileCheck %s -// Bytecode currently does not support big-endian platforms -// UNSUPPORTED: target=s390x-{{.*}} - // CHECK-LABEL: @TestDialectResources module @TestDialectResources attributes { // CHECK: bytecode.test = dense_resource : tensor<2xui32> Index: mlir/test/Bytecode/versioning/versioned_attr.mlir =================================================================== --- mlir/test/Bytecode/versioning/versioned_attr.mlir +++ mlir/test/Bytecode/versioning/versioned_attr.mlir @@ -1,9 +1,6 @@ // This file contains a test case representative of a dialect parsing an // attribute with versioned custom encoding. -// Bytecode currently does not support big-endian platforms -// UNSUPPORTED: target=s390x-{{.*}} - //===--------------------------------------------------------------------===// // Test attribute upgrade //===--------------------------------------------------------------------===// Index: mlir/test/Bytecode/versioning/versioned_bytecode.mlir =================================================================== --- mlir/test/Bytecode/versioning/versioned_bytecode.mlir +++ mlir/test/Bytecode/versioning/versioned_bytecode.mlir @@ -1,8 +1,5 @@ // This file contains test cases related to roundtripping. -// Bytecode currently does not support big-endian platforms -// UNSUPPORTED: target=s390x-{{.*}} - //===--------------------------------------------------------------------===// // Test roundtrip //===--------------------------------------------------------------------===// Index: mlir/test/Bytecode/versioning/versioned_op.mlir =================================================================== --- mlir/test/Bytecode/versioning/versioned_op.mlir +++ mlir/test/Bytecode/versioning/versioned_op.mlir @@ -1,9 +1,6 @@ // This file contains test cases related to the dialect post-parsing upgrade // mechanism. -// Bytecode currently does not support big-endian platforms -// UNSUPPORTED: target=s390x-{{.*}} - //===--------------------------------------------------------------------===// // Test generic //===--------------------------------------------------------------------===// Index: mlir/test/Dialect/Builtin/Bytecode/attrs.mlir =================================================================== --- mlir/test/Dialect/Builtin/Bytecode/attrs.mlir +++ mlir/test/Dialect/Builtin/Bytecode/attrs.mlir @@ -1,8 +1,5 @@ // RUN: mlir-opt -emit-bytecode -allow-unregistered-dialect %s | mlir-opt -allow-unregistered-dialect -mlir-print-local-scope | FileCheck %s -// Bytecode currently does not support big-endian platforms -// UNSUPPORTED: target=s390x-{{.*}} - //===----------------------------------------------------------------------===// // ArrayAttr //===----------------------------------------------------------------------===// Index: mlir/test/Dialect/Builtin/Bytecode/types.mlir =================================================================== --- mlir/test/Dialect/Builtin/Bytecode/types.mlir +++ mlir/test/Dialect/Builtin/Bytecode/types.mlir @@ -1,8 +1,5 @@ // RUN: mlir-opt -emit-bytecode %s | mlir-opt | FileCheck %s -// Bytecode currently does not support big-endian platforms -// UNSUPPORTED: target=s390x-{{.*}} - //===----------------------------------------------------------------------===// // ComplexType //===----------------------------------------------------------------------===// Index: mlir/test/Dialect/Quant/Bytecode/types.mlir =================================================================== --- mlir/test/Dialect/Quant/Bytecode/types.mlir +++ mlir/test/Dialect/Quant/Bytecode/types.mlir @@ -1,8 +1,5 @@ // RUN: mlir-opt -emit-bytecode %s | mlir-opt | FileCheck %s -// Bytecode currently does not support big-endian platforms -// UNSUPPORTED: target=s390x-{{.*}} - //===----------------------------------------------------------------------===// // AnyQuantized //===----------------------------------------------------------------------===// Index: mlir/unittests/Bytecode/BytecodeTest.cpp =================================================================== --- mlir/unittests/Bytecode/BytecodeTest.cpp +++ mlir/unittests/Bytecode/BytecodeTest.cpp @@ -15,6 +15,7 @@ #include "mlir/Parser/Parser.h" #include "llvm/ADT/StringRef.h" +#include "llvm/Support/Endian.h" #include "gmock/gmock.h" #include "gtest/gtest.h" @@ -54,6 +55,12 @@ parseSourceString(ostream.str(), parseConfig); ASSERT_TRUE(roundTripModule); + // FIXME: Parsing external resources does not work on big-endian + // platforms currently. + if (llvm::support::endian::system_endianness() == + llvm::support::endianness::big) + GTEST_SKIP(); + // Try to see if we have a valid resource in the parsed module. auto checkResourceAttribute = [&](Operation *op) { Attribute attr = roundTripModule->getAttr("bytecode.test");