13 #ifndef MLIR_BYTECODE_BYTECODEWRITER_H
14 #define MLIR_BYTECODE_BYTECODEWRITER_H
19 class DialectBytecodeWriter;
34 virtual LogicalResult
write(T entry, std::optional<StringRef> &name,
43 std::optional<StringRef> dummy;
44 return write(entry, dummy, writer);
49 template <
typename CallableT,
50 std::enable_if_t<std::is_convertible_v<
51 CallableT, std::function<LogicalResult(
52 T, std::optional<StringRef> &,
55 static std::unique_ptr<AttrTypeBytecodeWriter<T>>
58 Processor(CallableT &&writeFn)
60 LogicalResult
write(T entry, std::optional<StringRef> &name,
62 return writeFn(entry, name, writer);
65 std::decay_t<CallableT> writeFn;
67 return std::make_unique<Processor>(std::forward<CallableT>(writeFn));
83 StringRef producer =
"MLIR" LLVM_VERSION_STRING);
102 llvm::StringMap<std::unique_ptr<DialectVersion>> &
109 std::move(dialectVersion));
112 std::unique_ptr<DialectVersion> dialectVersion)
const;
133 template <
typename CallableT>
134 std::enable_if_t<std::is_convertible_v<
136 std::function<LogicalResult(
Attribute, std::optional<StringRef> &,
140 std::forward<CallableT>(emitFn)));
142 template <
typename CallableT>
143 std::enable_if_t<std::is_convertible_v<
144 CallableT, std::function<LogicalResult(
Type, std::optional<StringRef> &,
148 std::forward<CallableT>(emitFn)));
163 template <
typename CallableT>
164 std::enable_if_t<std::is_convertible<
168 name, std::forward<CallableT>(printFn)));
180 std::unique_ptr<Impl>
impl;
191 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.