13 #ifndef MLIR_BYTECODE_BYTECODEWRITER_H
14 #define MLIR_BYTECODE_BYTECODEWRITER_H
17 #include "llvm/Config/llvm-config.h"
20 class DialectBytecodeWriter;
35 virtual LogicalResult
write(T entry, std::optional<StringRef> &name,
44 std::optional<StringRef> dummy;
45 return write(entry, dummy, writer);
50 template <
typename CallableT,
51 std::enable_if_t<std::is_convertible_v<
52 CallableT, std::function<LogicalResult(
53 T, std::optional<StringRef> &,
56 static std::unique_ptr<AttrTypeBytecodeWriter<T>>
59 Processor(CallableT &&writeFn)
61 LogicalResult
write(T entry, std::optional<StringRef> &name,
63 return writeFn(entry, name, writer);
66 std::decay_t<CallableT> writeFn;
68 return std::make_unique<Processor>(std::forward<CallableT>(writeFn));
84 StringRef producer =
"MLIR" LLVM_VERSION_STRING);
103 llvm::StringMap<std::unique_ptr<DialectVersion>> &
110 std::move(dialectVersion));
113 std::unique_ptr<DialectVersion> dialectVersion)
const;
134 template <
typename CallableT>
135 std::enable_if_t<std::is_convertible_v<
137 std::function<LogicalResult(
Attribute, std::optional<StringRef> &,
141 std::forward<CallableT>(emitFn)));
143 template <
typename CallableT>
144 std::enable_if_t<std::is_convertible_v<
145 CallableT, std::function<LogicalResult(
Type, std::optional<StringRef> &,
149 std::forward<CallableT>(emitFn)));
164 template <
typename CallableT>
165 std::enable_if_t<std::is_convertible<
169 name, std::forward<CallableT>(printFn)));
181 std::unique_ptr<Impl>
impl;
192 const BytecodeWriterConfig &config = {});
This class is used to build resource entries for use by the printer.
static std::unique_ptr< AsmResourcePrinter > fromCallable(StringRef name, CallableT &&printFn)
Return a resource printer implemented via the given callable, whose form should match that of buildRe...
A class to interact with the attributes and types printer when emitting MLIR bytecode.
virtual ~AttrTypeBytecodeWriter()=default
LogicalResult write(T entry, DialectBytecodeWriter &writer)
Callback writer API used in BytecodeWriter, where groups are created and type/attribute components ar...
AttrTypeBytecodeWriter()=default
static std::unique_ptr< AttrTypeBytecodeWriter< T > > fromCallable(CallableT &&writeFn)
Return an Attribute/Type printer implemented via the given callable, whose form should match that of ...
virtual LogicalResult write(T entry, std::optional< StringRef > &name, DialectBytecodeWriter &writer)=0
Callback writer API used in IRNumbering, where groups are created and type/attribute components are n...
Attributes are known-constant values of operations.
This class contains the configuration used for the bytecode writer.
void attachTypeCallback(std::unique_ptr< AttrTypeBytecodeWriter< Type >> callback)
std::enable_if_t< std::is_convertible_v< CallableT, std::function< LogicalResult(Attribute, std::optional< StringRef > &, DialectBytecodeWriter &)> > > attachAttributeCallback(CallableT &&emitFn)
Attach a custom bytecode printer callback to the configuration for the emission of custom type/attrib...
llvm::StringMap< std::unique_ptr< DialectVersion > > & getDialectVersionMap() const
A map containing the dialect versions to emit.
void setDialectVersion(StringRef dialectName, std::unique_ptr< DialectVersion > dialectVersion) const
void setElideResourceDataFlag(bool shouldElideResourceData=true)
Set a boolean flag to skip emission of resources into the bytecode file.
BytecodeWriterConfig(StringRef producer="MLIR" LLVM_VERSION_STRING)
producer is an optional string that can be used to identify the producer of the bytecode when reading...
void attachFallbackResourcePrinter(FallbackAsmResourceMap &map)
Attach resource printers to the AsmState for the fallback resources in the given map.
int64_t getDesiredBytecodeVersion() const
Get the set desired bytecode version to emit.
void setDialectVersion(std::unique_ptr< DialectVersion > dialectVersion) const
Set a given dialect version to emit on the map.
std::enable_if_t< std::is_convertible< CallableT, function_ref< void(Operation *, AsmResourceBuilder &)> >::value > attachResourcePrinter(StringRef name, CallableT &&printFn)
Attach an resource printer, in the form of a callable, to the configuration.
ArrayRef< std::unique_ptr< AttrTypeBytecodeWriter< Type > > > getTypeWriterCallbacks() const
ArrayRef< std::unique_ptr< AttrTypeBytecodeWriter< Attribute > > > getAttributeWriterCallbacks() const
Retrieve the callbacks.
void setDesiredBytecodeVersion(int64_t bytecodeVersion)
Set the desired bytecode version to emit.
const Impl & getImpl() const
Return an instance of the internal implementation.
std::enable_if_t< std::is_convertible_v< CallableT, std::function< LogicalResult(Type, std::optional< StringRef > &, DialectBytecodeWriter &)> > > attachTypeCallback(CallableT &&emitFn)
void attachResourcePrinter(std::unique_ptr< AsmResourcePrinter > printer)
Attach the given resource printer to the writer configuration.
void attachAttributeCallback(std::unique_ptr< AttrTypeBytecodeWriter< Attribute >> callback)
Attach a custom bytecode printer callback to the configuration for the emission of custom type/attrib...
This class defines a virtual interface for writing to a bytecode stream, providing hooks into the byt...
A fallback map containing external resources not explicitly handled by another parser/printer.
std::vector< std::unique_ptr< AsmResourcePrinter > > getPrinters()
Build a set of resource printers to print the resources within this map.
Operation is the basic unit of execution within MLIR.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Include the generated interface declarations.
LogicalResult writeBytecodeToFile(Operation *op, raw_ostream &os, const BytecodeWriterConfig &config={})
Write the bytecode for the given operation to the provided output stream.