[Mlir-commits] [mlir] de9a726 - Read/write external resource alignment tag in little-endian

Ulrich Weigand llvmlistbot at llvm.org
Tue Jul 12 00:37:15 PDT 2022


Author: Ulrich Weigand
Date: 2022-07-12T09:36:53+02:00
New Revision: de9a7260aca314778da7f768cd4d8687defc759a

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

LOG: Read/write external resource alignment tag in little-endian

https://reviews.llvm.org/D126446 added support for encoding
binary blobs in MLIR assembly.  To enable cross-architecture
compatibility, these need to be encoded in little-endian format.

This patch is a first step in that direction by reading and
writing the alignment tag that those blobs are prefixed by
in little-endian format.  This fixes assertion failures in
several test cases on big-endian platforms.

The actual content of the blob is not yet handled here.

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

Added: 
    

Modified: 
    mlir/lib/IR/AsmPrinter.cpp
    mlir/lib/Parser/Parser.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/IR/AsmPrinter.cpp b/mlir/lib/IR/AsmPrinter.cpp
index c3bc7ab1a2c1b..1e46b11195865 100644
--- a/mlir/lib/IR/AsmPrinter.cpp
+++ b/mlir/lib/IR/AsmPrinter.cpp
@@ -2685,8 +2685,9 @@ class OperationPrinter : public AsmPrinter::Impl, private OpAsmPrinter {
                    uint32_t dataAlignment) final {
       printFn(key, [&](raw_ostream &os) {
         // Store the blob in a hex string containing the alignment and the data.
+        llvm::support::ulittle32_t dataAlignmentLE(dataAlignment);
         os << "\"0x"
-           << llvm::toHex(StringRef(reinterpret_cast<char *>(&dataAlignment),
+           << llvm::toHex(StringRef(reinterpret_cast<char *>(&dataAlignmentLE),
                                     sizeof(dataAlignment)))
            << llvm::toHex(StringRef(data.data(), data.size())) << "\"";
       });

diff  --git a/mlir/lib/Parser/Parser.cpp b/mlir/lib/Parser/Parser.cpp
index e27f72c221714..bf015de2ef0a3 100644
--- a/mlir/lib/Parser/Parser.cpp
+++ b/mlir/lib/Parser/Parser.cpp
@@ -24,6 +24,7 @@
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/StringSet.h"
 #include "llvm/ADT/bit.h"
+#include "llvm/Support/Endian.h"
 #include "llvm/Support/PrettyStackTrace.h"
 #include "llvm/Support/SourceMgr.h"
 #include <algorithm>
@@ -2349,7 +2350,7 @@ class ParsedResourceEntry : public AsmParsedResourceEntry {
                          "expected hex string blob for key '" + key +
                              "' to encode alignment in first 4 bytes");
     }
-    uint32_t align = 0;
+    llvm::support::ulittle32_t align;
     memcpy(&align, blobData->data(), sizeof(uint32_t));
 
     // Get the data portion of the blob.


        


More information about the Mlir-commits mailing list