Files
clang-p2996/mlir/lib/Bytecode/Encoding.h
River Riddle f3acb54c1b [mlir] Add initial support for a binary serialization format
This commit adds a new bytecode serialization format for MLIR.
The actual serialization of MLIR to binary is relatively straightforward,
given the very very general structure of MLIR. The underlying basis for
this format is a variable-length encoding for integers, which gets heavily
used for nearly all aspects of the encoding (given that most of the encoding
is just indexing into lists).

The format currently does not provide support for custom attribute/type
serialization, and thus always uses an assembly format fallback. It also
doesn't provide support for resources. These will be added in followups,
the intention for this patch is to provide something that supports the
basic cases, and can be built on top of.

https://discourse.llvm.org/t/rfc-a-binary-serialization-format-for-mlir/63518

Differential Revision: https://reviews.llvm.org/D131747
2022-08-22 00:36:26 -07:00

82 lines
2.4 KiB
C++

//===- Encoding.h - MLIR binary format encoding information -----*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This header defines enum values describing the structure of MLIR bytecode
// files.
//
//===----------------------------------------------------------------------===//
#ifndef LIB_MLIR_BYTECODE_ENCODING_H
#define LIB_MLIR_BYTECODE_ENCODING_H
#include <cstdint>
namespace mlir {
namespace bytecode {
//===----------------------------------------------------------------------===//
// General constants
//===----------------------------------------------------------------------===//
enum {
/// The current bytecode version.
kVersion = 0,
};
//===----------------------------------------------------------------------===//
// Sections
//===----------------------------------------------------------------------===//
namespace Section {
enum ID : uint8_t {
/// This section contains strings referenced within the bytecode.
kString = 0,
/// This section contains the dialects referenced within an IR module.
kDialect = 1,
/// This section contains the attributes and types referenced within an IR
/// module.
kAttrType = 2,
/// This section contains the offsets for the attribute and types within the
/// AttrType section.
kAttrTypeOffset = 3,
/// This section contains the list of operations serialized into the bytecode,
/// and their nested regions/operations.
kIR = 4,
/// The total number of section types.
kNumSections = 5,
};
} // namespace Section
//===----------------------------------------------------------------------===//
// IR Section
//===----------------------------------------------------------------------===//
/// This enum represents a mask of all of the potential components of an
/// operation. This mask is used when encoding an operation to indicate which
/// components are present in the bytecode.
namespace OpEncodingMask {
enum : uint8_t {
// clang-format off
kHasAttrs = 0b00000001,
kHasResults = 0b00000010,
kHasOperands = 0b00000100,
kHasSuccessors = 0b00001000,
kHasInlineRegions = 0b00010000,
// clang-format on
};
} // namespace OpEncodingMask
} // namespace bytecode
} // namespace mlir
#endif