Skip to content

Commit

Permalink
Read/write external resource alignment tag in little-endian
Browse files Browse the repository at this point in the history
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
  • Loading branch information
uweigand committed Jul 12, 2022
1 parent af40f99 commit de9a726
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion mlir/lib/IR/AsmPrinter.cpp
Expand Up @@ -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())) << "\"";
});
Expand Down
3 changes: 2 additions & 1 deletion mlir/lib/Parser/Parser.cpp
Expand Up @@ -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>
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit de9a726

Please sign in to comment.